use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.
the class StaticLayout_Delegate method nComputeLineBreaks.
@LayoutlibDelegate
static /*package*/
int nComputeLineBreaks(long nativeBuilder, LineBreaks recycle, int[] recycleBreaks, float[] recycleWidths, int[] recycleFlags, int recycleLength) {
Builder builder = sBuilderManager.getDelegate(nativeBuilder);
if (builder == null) {
return 0;
}
// compute all possible breakpoints.
int length = builder.mWidths.length;
BreakIterator it = BreakIterator.getLineInstance(new ULocale(builder.mLocale));
it.setText(new Segment(builder.mText, 0, length));
// average word length in english is 5. So, initialize the possible breaks with a guess.
List<Integer> breaks = new ArrayList<Integer>((int) Math.ceil(length / 5d));
int loc;
it.first();
while ((loc = it.next()) != BreakIterator.DONE) {
breaks.add(loc);
}
List<Primitive> primitives = computePrimitives(builder.mText, builder.mWidths, length, breaks);
switch(builder.mBreakStrategy) {
case Layout.BREAK_STRATEGY_SIMPLE:
builder.mLineBreaker = new GreedyLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
break;
case Layout.BREAK_STRATEGY_HIGH_QUALITY:
// break;
case Layout.BREAK_STRATEGY_BALANCED:
builder.mLineBreaker = new OptimizingLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
break;
default:
throw new AssertionError("Unknown break strategy: " + builder.mBreakStrategy);
}
builder.mLineBreaker.computeBreaks(recycle);
return recycle.breaks.length;
}
use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.
the class PathParser_Delegate method nCreatePathFromPathData.
@LayoutlibDelegate
static /*package*/
void nCreatePathFromPathData(long outPathPtr, long pathData) {
Path_Delegate path_delegate = Path_Delegate.getDelegate(outPathPtr);
PathParser_Delegate source = sManager.getDelegate(outPathPtr);
if (source == null || path_delegate == null) {
return;
}
PathDataNode.nodesToPath(source.mPathDataNodes, path_delegate);
}
use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.
the class FontFamily_Delegate method nAddFontFromAsset.
@LayoutlibDelegate
static /*package*/
boolean nAddFontFromAsset(long nativeFamily, AssetManager mgr, String path) {
FontFamily_Delegate ffd = sManager.getDelegate(nativeFamily);
if (ffd == null) {
return false;
}
ffd.mValid = true;
if (mgr == null) {
return false;
}
if (mgr instanceof BridgeAssetManager) {
InputStream fontStream = null;
try {
AssetRepository assetRepository = ((BridgeAssetManager) mgr).getAssetRepository();
if (assetRepository == null) {
Bridge.getLog().error(LayoutLog.TAG_MISSING_ASSET, "Asset not found: " + path, null);
return false;
}
if (!assetRepository.isSupported()) {
// Don't log any warnings on unsupported IDEs.
return false;
}
// Check cache
FontInfo fontInfo = sCache.get(path);
if (fontInfo != null) {
// renew the font's lease.
sCache.put(path, fontInfo);
ffd.addFont(fontInfo);
return true;
}
fontStream = assetRepository.openAsset(path, AssetManager.ACCESS_STREAMING);
if (fontStream == null) {
Bridge.getLog().error(LayoutLog.TAG_MISSING_ASSET, "Asset not found: " + path, path);
return false;
}
Font font = Font.createFont(Font.TRUETYPE_FONT, fontStream);
fontInfo = new FontInfo();
fontInfo.mFont = font;
fontInfo.mWeight = font.isBold() ? BOLD_FONT_WEIGHT : DEFAULT_FONT_WEIGHT;
fontInfo.mIsItalic = font.isItalic();
ffd.addFont(fontInfo);
return true;
} catch (IOException e) {
Bridge.getLog().error(LayoutLog.TAG_MISSING_ASSET, "Unable to load font " + path, e, path);
} catch (FontFormatException e) {
if (path.endsWith(EXTENSION_OTF)) {
// otf fonts are not supported on the user's config (JRE version + OS)
Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, "OpenType fonts are not supported yet: " + path, null, path);
} else {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Unable to load font " + path, e, path);
}
} finally {
if (fontStream != null) {
try {
fontStream.close();
} catch (IOException ignored) {
}
}
}
return false;
}
// This should never happen. AssetManager is a final class (from user's perspective), and
// we've replaced every creation of AssetManager with our implementation. We create an
// exception and log it, but continue with rest of the rendering, without loading this font.
Bridge.getLog().error(LayoutLog.TAG_BROKEN, "You have found a bug in the rendering library. Please file a bug at b.android.com.", new RuntimeException("Asset Manager is not an instance of BridgeAssetManager"), null);
return false;
}
use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.
the class Matrix_Delegate method native_invert.
@LayoutlibDelegate
static /*package*/
boolean native_invert(long native_object, long inverse) {
Matrix_Delegate d = sManager.getDelegate(native_object);
if (d == null) {
return false;
}
Matrix_Delegate inv_mtx = sManager.getDelegate(inverse);
if (inv_mtx == null) {
return false;
}
try {
AffineTransform affineTransform = d.getAffineTransform();
AffineTransform inverseTransform = affineTransform.createInverse();
inv_mtx.mValues[0] = (float) inverseTransform.getScaleX();
inv_mtx.mValues[1] = (float) inverseTransform.getShearX();
inv_mtx.mValues[2] = (float) inverseTransform.getTranslateX();
inv_mtx.mValues[3] = (float) inverseTransform.getScaleX();
inv_mtx.mValues[4] = (float) inverseTransform.getShearY();
inv_mtx.mValues[5] = (float) inverseTransform.getTranslateY();
return true;
} catch (NoninvertibleTransformException e) {
return false;
}
}
use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.
the class Paint_Delegate method nHasGlyph.
@LayoutlibDelegate
static /*package*/
boolean nHasGlyph(long nativePaint, long nativeTypeface, int bidiFlags, String string) {
Paint_Delegate delegate = sManager.getDelegate(nativePaint);
if (delegate == null) {
return false;
}
if (string.length() == 0) {
return false;
}
if (string.length() > 1) {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_TEXT_RENDERING, "Paint.hasGlyph() is not supported for ligatures.", null, null);
return false;
}
assert nativeTypeface == delegate.mNativeTypeface;
Typeface_Delegate typeface_delegate = Typeface_Delegate.getDelegate(nativeTypeface);
char c = string.charAt(0);
for (Font font : typeface_delegate.getFonts(delegate.mFontVariant)) {
if (font.canDisplay(c)) {
return true;
}
}
return false;
}
Aggregations