Search in sources :

Example 1 with Font

use of com.airbnb.lottie.model.Font in project lottie-android by airbnb.

the class LottieDrawableTest method createComposition.

@SuppressWarnings("SameParameterValue")
private LottieComposition createComposition(int startFrame, int endFrame) {
    LottieComposition composition = new LottieComposition();
    composition.init(new Rect(), startFrame, endFrame, 1000, new ArrayList<Layer>(), new LongSparseArray<Layer>(0), new HashMap<String, List<Layer>>(0), new HashMap<String, LottieImageAsset>(0), new SparseArrayCompat<FontCharacter>(0), new HashMap<String, Font>(0), new ArrayList<Marker>());
    return composition;
}
Also used : Rect(android.graphics.Rect) Marker(com.airbnb.lottie.model.Marker) Layer(com.airbnb.lottie.model.layer.Layer) FontCharacter(com.airbnb.lottie.model.FontCharacter) Font(com.airbnb.lottie.model.Font) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Font

use of com.airbnb.lottie.model.Font in project lottie-android by airbnb.

the class LottieValueAnimatorUnitTest method createComposition.

private LottieComposition createComposition(int startFrame, int endFrame) {
    LottieComposition composition = new LottieComposition();
    composition.init(new Rect(), startFrame, endFrame, 1000, new ArrayList<Layer>(), new LongSparseArray<Layer>(0), new HashMap<String, List<Layer>>(0), new HashMap<String, LottieImageAsset>(0), new SparseArrayCompat<FontCharacter>(0), new HashMap<String, Font>(0), new ArrayList<Marker>());
    return composition;
}
Also used : Rect(android.graphics.Rect) Marker(com.airbnb.lottie.model.Marker) Layer(com.airbnb.lottie.model.layer.Layer) FontCharacter(com.airbnb.lottie.model.FontCharacter) Font(com.airbnb.lottie.model.Font) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Font

use of com.airbnb.lottie.model.Font in project lottie-android by airbnb.

the class TextLayer method drawLayer.

@Override
void drawLayer(Canvas canvas, Matrix parentMatrix, int parentAlpha) {
    canvas.save();
    if (!lottieDrawable.useTextGlyphs()) {
        canvas.concat(parentMatrix);
    }
    DocumentData documentData = textAnimation.getValue();
    Font font = composition.getFonts().get(documentData.fontName);
    if (font == null) {
        // Something is wrong.
        canvas.restore();
        return;
    }
    if (colorCallbackAnimation != null) {
        fillPaint.setColor(colorCallbackAnimation.getValue());
    } else if (colorAnimation != null) {
        fillPaint.setColor(colorAnimation.getValue());
    } else {
        fillPaint.setColor(documentData.color);
    }
    if (strokeColorCallbackAnimation != null) {
        strokePaint.setColor(strokeColorCallbackAnimation.getValue());
    } else if (strokeColorAnimation != null) {
        strokePaint.setColor(strokeColorAnimation.getValue());
    } else {
        strokePaint.setColor(documentData.strokeColor);
    }
    int opacity = transform.getOpacity() == null ? 100 : transform.getOpacity().getValue();
    int alpha = opacity * 255 / 100;
    fillPaint.setAlpha(alpha);
    strokePaint.setAlpha(alpha);
    if (strokeWidthCallbackAnimation != null) {
        strokePaint.setStrokeWidth(strokeWidthCallbackAnimation.getValue());
    } else if (strokeWidthAnimation != null) {
        strokePaint.setStrokeWidth(strokeWidthAnimation.getValue());
    } else {
        float parentScale = Utils.getScale(parentMatrix);
        strokePaint.setStrokeWidth(documentData.strokeWidth * Utils.dpScale() * parentScale);
    }
    if (lottieDrawable.useTextGlyphs()) {
        drawTextGlyphs(documentData, parentMatrix, font, canvas);
    } else {
        drawTextWithFont(documentData, font, canvas);
    }
    canvas.restore();
}
Also used : DocumentData(com.airbnb.lottie.model.DocumentData) Font(com.airbnb.lottie.model.Font) Paint(android.graphics.Paint)

Example 4 with Font

use of com.airbnb.lottie.model.Font in project lottie-android by airbnb.

the class LottieCompositionMoshiParser method parse.

public static LottieComposition parse(JsonReader reader) throws IOException {
    float scale = Utils.dpScale();
    float startFrame = 0f;
    float endFrame = 0f;
    float frameRate = 0f;
    final LongSparseArray<Layer> layerMap = new LongSparseArray<>();
    final List<Layer> layers = new ArrayList<>();
    int width = 0;
    int height = 0;
    Map<String, List<Layer>> precomps = new HashMap<>();
    Map<String, LottieImageAsset> images = new HashMap<>();
    Map<String, Font> fonts = new HashMap<>();
    List<Marker> markers = new ArrayList<>();
    SparseArrayCompat<FontCharacter> characters = new SparseArrayCompat<>();
    LottieComposition composition = new LottieComposition();
    reader.beginObject();
    while (reader.hasNext()) {
        switch(reader.selectName(NAMES)) {
            case 0:
                width = reader.nextInt();
                break;
            case 1:
                height = reader.nextInt();
                break;
            case 2:
                startFrame = (float) reader.nextDouble();
                break;
            case 3:
                endFrame = (float) reader.nextDouble() - 0.01f;
                break;
            case 4:
                frameRate = (float) reader.nextDouble();
                break;
            case 5:
                String version = reader.nextString();
                String[] versions = version.split("\\.");
                int majorVersion = Integer.parseInt(versions[0]);
                int minorVersion = Integer.parseInt(versions[1]);
                int patchVersion = Integer.parseInt(versions[2]);
                if (!Utils.isAtLeastVersion(majorVersion, minorVersion, patchVersion, 4, 4, 0)) {
                    composition.addWarning("Lottie only supports bodymovin >= 4.4.0");
                }
                break;
            case 6:
                parseLayers(reader, composition, layers, layerMap);
                break;
            case 7:
                parseAssets(reader, composition, precomps, images);
                break;
            case 8:
                parseFonts(reader, fonts);
                break;
            case 9:
                parseChars(reader, composition, characters);
                break;
            case 10:
                parseMarkers(reader, markers);
                break;
            default:
                reader.skipName();
                reader.skipValue();
        }
    }
    int scaledWidth = (int) (width * scale);
    int scaledHeight = (int) (height * scale);
    Rect bounds = new Rect(0, 0, scaledWidth, scaledHeight);
    composition.init(bounds, startFrame, endFrame, frameRate, layers, layerMap, precomps, images, characters, fonts, markers);
    return composition;
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) Rect(android.graphics.Rect) HashMap(java.util.HashMap) LottieImageAsset(com.airbnb.lottie.LottieImageAsset) ArrayList(java.util.ArrayList) Marker(com.airbnb.lottie.model.Marker) Layer(com.airbnb.lottie.model.layer.Layer) Font(com.airbnb.lottie.model.Font) FontCharacter(com.airbnb.lottie.model.FontCharacter) ArrayList(java.util.ArrayList) List(java.util.List) LottieComposition(com.airbnb.lottie.LottieComposition) SparseArrayCompat(androidx.collection.SparseArrayCompat)

Example 5 with Font

use of com.airbnb.lottie.model.Font in project lottie-android by airbnb.

the class LottieCompositionMoshiParser method parseFonts.

private static void parseFonts(JsonReader reader, Map<String, Font> fonts) throws IOException {
    reader.beginObject();
    while (reader.hasNext()) {
        switch(reader.selectName(FONT_NAMES)) {
            case 0:
                reader.beginArray();
                while (reader.hasNext()) {
                    Font font = FontParser.parse(reader);
                    fonts.put(font.getName(), font);
                }
                reader.endArray();
                break;
            default:
                reader.skipName();
                reader.skipValue();
        }
    }
    reader.endObject();
}
Also used : Font(com.airbnb.lottie.model.Font)

Aggregations

Font (com.airbnb.lottie.model.Font)5 Rect (android.graphics.Rect)3 FontCharacter (com.airbnb.lottie.model.FontCharacter)3 Marker (com.airbnb.lottie.model.Marker)3 Layer (com.airbnb.lottie.model.layer.Layer)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Paint (android.graphics.Paint)1 LongSparseArray (androidx.collection.LongSparseArray)1 SparseArrayCompat (androidx.collection.SparseArrayCompat)1 LottieComposition (com.airbnb.lottie.LottieComposition)1 LottieImageAsset (com.airbnb.lottie.LottieImageAsset)1 DocumentData (com.airbnb.lottie.model.DocumentData)1 HashMap (java.util.HashMap)1