content: package androidx.core.graphics;
  
  import android.content.ContentResolver;
  import android.content.Context;
  import android.content.res.Resources;
  import android.graphics.Typeface;
  import android.graphics.fonts.Font;
  import android.graphics.fonts.FontFamily;
  import android.graphics.fonts.FontStyle;
  import android.os.CancellationSignal;
  import android.os.ParcelFileDescriptor;
  import androidx.constraintlayout.core.motion.utils.TypedValues;
  import androidx.core.content.res.FontResourcesParserCompat;
  import androidx.core.provider.FontsContractCompat;
  import java.io.IOException;
  import java.io.InputStream;
  
  public class TypefaceCompatApi29Impl extends TypefaceCompatBaseImpl {
      private Font findBaseFont(FontFamily family, int style) {
          FontStyle fontStyle = new FontStyle((style & 1) != 0 ? TypedValues.TransitionType.TYPE_DURATION : 400, (style & 2) != 0 ? 1 : 0);
          Font font = family.getFont(0);
          int matchScore = getMatchScore(fontStyle, font.getStyle());
          for (int i = 1; i < family.getSize(); i++) {
              Font font2 = family.getFont(i);
              int matchScore2 = getMatchScore(fontStyle, font2.getStyle());
              if (matchScore2 < matchScore) {
                  font = font2;
                  matchScore = matchScore2;
              }
          }
          return font;
      }
  
      private static int getMatchScore(FontStyle o1, FontStyle o2) {
          return (Math.abs(o1.getWeight() - o2.getWeight()) / 100) + (o1.getSlant() == o2.getSlant() ? 0 : 2);
      }
  
      public Typeface createFromFontFamilyFilesResourceEntry(Context context, FontResourcesParserCompat.FontFamilyFilesResourceEntry familyEntry, Resources resources, int style) {
          FontFamily.Builder builder = null;
          try {
              for (FontResourcesParserCompat.FontFileResourceEntry fontFileResourceEntry : familyEntry.getEntries()) {
                  try {
                      Font build = new Font.Builder(resources, fontFileResourceEntry.getResourceId()).setWeight(fontFileResourceEntry.getWeight()).setSlant(fontFileResourceEntry.isItalic() ? 1 : 0).setTtcIndex(fontFileResourceEntry.getTtcIndex()).setFontVariationSettings(fontFileResourceEntry.getVariationSettings()).build();
                      if (builder == null) {
                          builder = new FontFamily.Builder(build);
                      } else {
                          builder.addFont(build);
                      }
                  } catch (IOException e) {
                  }
              }
              if (builder == null) {
                  return null;
              }
              FontFamily build2 = builder.build();
              return new Typeface.CustomFallbackBuilder(build2).setStyle(findBaseFont(build2, style).getStyle()).build();
          } catch (Exception e2) {
              return null;
          }
      }
  
      public Typeface createFromFontInfo(Context context, CancellationSignal cancellationSignal, FontsContractCompat.FontInfo[] fonts, int style) {
          ParcelFileDescriptor openFileDescriptor;
          FontFamily.Builder builder = null;
          ContentResolver contentResolver = context.getContentResolver();
          try {
              for (FontsContractCompat.FontInfo fontInfo : fonts) {
                  try {
                      openFileDescriptor = contentResolver.openFileDescriptor(fontInfo.getUri(), "r", cancellationSignal);
                      if (openFileDescriptor != null) {
                          Font build = new Font.Builder(openFileDescriptor).setWeight(fontInfo.getWeight()).setSlant(fontInfo.isItalic() ? 1 : 0).setTtcIndex(fontInfo.getTtcIndex()).build();
                          if (builder == null) {
                              builder = new FontFamily.Builder(build);
                          } else {
                              builder.addFont(build);
                          }
                          if (openFileDescriptor != null) {
                              openFileDescriptor.close();
                          }
                      } else if (openFileDescriptor != null) {
                          openFileDescriptor.close();
                      }
                  } catch (IOException e) {
                  } catch (Throwable th) {
                      th.addSuppressed(th);
                  }
              }
              if (builder == null) {
                  return null;
              }
              FontFamily build2 = builder.build();
              return new Typeface.CustomFallbackBuilder(build2).setStyle(findBaseFont(build2, style).getStyle()).build();
              throw th;
          } catch (Exception e2) {
              return null;
          }
      }
  
      /* access modifiers changed from: protected */
      public Typeface createFromInputStream(Context context, InputStream is) {
          throw new RuntimeException("Do not use this function in API 29 or later.");
      }
  
      public Typeface createFromResourcesFontFile(Context context, Resources resources, int id, String path, int style) {
          try {
              Font build = new Font.Builder(resources, id).build();
              return new Typeface.CustomFallbackBuilder(new FontFamily.Builder(build).build()).setStyle(build.getStyle()).build();
          } catch (Exception e) {
              return null;
          }
      }
  
      /* access modifiers changed from: protected */
      public FontsContractCompat.FontInfo findBestInfo(FontsContractCompat.FontInfo[] fonts, int style) {
          throw new RuntimeException("Do not use this function in API 29 or later.");
      }
  }
  