package com.airbnb.lottie.manager; import android.content.res.AssetManager; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.view.View; import com.airbnb.lottie.FontAssetDelegate; import com.airbnb.lottie.model.MutablePair; import com.airbnb.lottie.utils.Logger; import java.util.HashMap; import java.util.Map; /* loaded from: classes.dex */ public class FontAssetManager { private final AssetManager assetManager; private FontAssetDelegate delegate; private final MutablePair tempPair = new MutablePair<>(); private final Map, Typeface> fontMap = new HashMap(); private final Map fontFamilies = new HashMap(); private String defaultFontFileExtension = ".ttf"; public FontAssetManager(Drawable.Callback callback, FontAssetDelegate fontAssetDelegate) { this.delegate = fontAssetDelegate; if (!(callback instanceof View)) { Logger.warning("LottieDrawable must be inside of a view for images to work."); this.assetManager = null; } else { this.assetManager = ((View) callback).getContext().getAssets(); } } public Typeface getTypeface(String str, String str2) { this.tempPair.set(str, str2); Typeface typeface = this.fontMap.get(this.tempPair); if (typeface != null) { return typeface; } Typeface typefaceForStyle = typefaceForStyle(getFontFamily(str), str2); this.fontMap.put(this.tempPair, typefaceForStyle); return typefaceForStyle; } private Typeface getFontFamily(String str) { String fontPath; Typeface typeface = this.fontFamilies.get(str); if (typeface != null) { return typeface; } FontAssetDelegate fontAssetDelegate = this.delegate; Typeface fetchFont = fontAssetDelegate != null ? fontAssetDelegate.fetchFont(str) : null; FontAssetDelegate fontAssetDelegate2 = this.delegate; if (fontAssetDelegate2 != null && fetchFont == null && (fontPath = fontAssetDelegate2.getFontPath(str)) != null) { fetchFont = Typeface.createFromAsset(this.assetManager, fontPath); } if (fetchFont == null) { StringBuilder sb = new StringBuilder("fonts/"); sb.append(str); sb.append(this.defaultFontFileExtension); fetchFont = Typeface.createFromAsset(this.assetManager, sb.toString()); } this.fontFamilies.put(str, fetchFont); return fetchFont; } private Typeface typefaceForStyle(Typeface typeface, String str) { boolean contains = str.contains("Italic"); boolean contains2 = str.contains("Bold"); int i = (contains && contains2) ? 3 : contains ? 2 : contains2 ? 1 : 0; return typeface.getStyle() == i ? typeface : Typeface.create(typeface, i); } public void setDelegate(FontAssetDelegate fontAssetDelegate) { this.delegate = fontAssetDelegate; } public void setDefaultFontFileExtension(String str) { this.defaultFontFileExtension = str; } }