Revert "Make CFX_FontMgr member variables private."
[pdfium.git] / core / src / fxge / ge / fx_ge_text.cpp
index 7a84330..6938bb9 100644 (file)
@@ -182,18 +182,20 @@ FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars,
   int nativetext_flags = text_flags;
   if (m_DeviceClass != FXDC_DISPLAY) {
     if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) {
+      bool should_call_draw_device_text = true;
 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
-      if (!(text_flags & FXFONT_CIDFONT) &&
-          pFont->GetPsName().Find(CFX_WideString::FromLocal("+ZJHL")) == -1)
-#ifdef FOXIT_CHROME_BUILD
-        if (pFont->GetPsName() != CFX_WideString::FromLocal("CNAAJI+cmex10"))
-#endif
+      if ((text_flags & FXFONT_CIDFONT) ||
+          (pFont->GetPsName().Find(CFX_WideString::FromLocal("+ZJHL")) != -1) ||
+          (pFont->GetPsName() == CFX_WideString::FromLocal("CNAAJI+cmex10"))) {
+        should_call_draw_device_text = false;
+      }
 #endif
-          if (m_pDeviceDriver->DrawDeviceText(
-                  nChars, pCharPos, pFont, pCache, pText2Device, font_size,
-                  fill_color, alpha_flag, pIccTransform)) {
-            return TRUE;
-          }
+      if (should_call_draw_device_text &&
+          m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache,
+                                          pText2Device, font_size, fill_color,
+                                          alpha_flag, pIccTransform)) {
+        return TRUE;
+      }
     }
     int alpha = FXGETFLAG_COLORTYPE(alpha_flag)
                     ? FXGETFLAG_ALPHA_FILL(alpha_flag)
@@ -202,17 +204,19 @@ FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars,
       return FALSE;
     }
   } else if (!(text_flags & FXTEXT_NO_NATIVETEXT)) {
+    bool should_call_draw_device_text = true;
 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
-    if (!(text_flags & FXFONT_CIDFONT))
-#ifdef FOXIT_CHROME_BUILD
-      if (pFont->GetPsName() != CFX_WideString::FromLocal("CNAAJI+cmex10"))
-#endif
+    if ((text_flags & FXFONT_CIDFONT) ||
+        (pFont->GetPsName() == CFX_WideString::FromLocal("CNAAJI+cmex10"))) {
+      should_call_draw_device_text = false;
+    }
 #endif
-        if (m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache,
-                                            pText2Device, font_size, fill_color,
-                                            alpha_flag, pIccTransform)) {
-          return TRUE;
-        }
+    if (should_call_draw_device_text &&
+        m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache,
+                                        pText2Device, font_size, fill_color,
+                                        alpha_flag, pIccTransform)) {
+      return TRUE;
+    }
   }
   CFX_AffineMatrix char2device, deviceCtm, text2Device;
   if (pText2Device) {
@@ -1228,15 +1232,11 @@ CFX_FaceCache::CFX_FaceCache(FXFT_Face face) {
   m_Face = face;
 }
 CFX_FaceCache::~CFX_FaceCache() {
-  FX_POSITION pos = m_SizeMap.GetStartPosition();
-  CFX_ByteString Key;
-  CFX_SizeGlyphCache* pSizeCache = NULL;
-  while (pos) {
-    m_SizeMap.GetNextAssoc(pos, Key, (void*&)pSizeCache);
-    delete pSizeCache;
+  for (const auto& pair : m_SizeMap) {
+    delete pair.second;
   }
-  m_SizeMap.RemoveAll();
-  pos = m_PathMap.GetStartPosition();
+  m_SizeMap.clear();
+  FX_POSITION pos = m_PathMap.GetStartPosition();
   void* key1;
   CFX_PathData* pPath;
   while (pos) {
@@ -1256,10 +1256,13 @@ CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap(
     FX_BOOL bFontStyle,
     int dest_width,
     int anti_alias) {
-  CFX_SizeGlyphCache* pSizeCache = NULL;
-  if (!m_SizeMap.Lookup(FaceGlyphsKey, (void*&)pSizeCache)) {
+  CFX_SizeGlyphCache* pSizeCache;
+  auto it = m_SizeMap.find(FaceGlyphsKey);
+  if (it == m_SizeMap.end()) {
     pSizeCache = new CFX_SizeGlyphCache;
-    m_SizeMap.SetAt(FaceGlyphsKey, pSizeCache);
+    m_SizeMap[FaceGlyphsKey] = pSizeCache;
+  } else {
+    pSizeCache = it->second;
   }
   CFX_GlyphBitmap* pGlyphBitmap = NULL;
   if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index,
@@ -1331,8 +1334,9 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(
                              bFontStyle, dest_width, anti_alias);
   }
   CFX_GlyphBitmap* pGlyphBitmap;
-  CFX_SizeGlyphCache* pSizeCache = NULL;
-  if (m_SizeMap.Lookup(FaceGlyphsKey, (void*&)pSizeCache)) {
+  auto it = m_SizeMap.find(FaceGlyphsKey);
+  if (it != m_SizeMap.end()) {
+    CFX_SizeGlyphCache* pSizeCache = it->second;
     if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index,
                                       (void*&)pGlyphBitmap)) {
       return pGlyphBitmap;
@@ -1347,8 +1351,8 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(
     pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix,
                                           dest_width, anti_alias);
     if (pGlyphBitmap) {
-      pSizeCache = new CFX_SizeGlyphCache;
-      m_SizeMap.SetAt(FaceGlyphsKey, pSizeCache);
+      CFX_SizeGlyphCache* pSizeCache = new CFX_SizeGlyphCache;
+      m_SizeMap[FaceGlyphsKey] = pSizeCache;
       pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap);
       return pGlyphBitmap;
     }
@@ -1643,109 +1647,6 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont,
   }
   return pGlyphBitmap;
 }
-FX_BOOL _OutputGlyph(void* dib,
-                     int x,
-                     int y,
-                     CFX_Font* pFont,
-                     int glyph_index,
-                     FX_ARGB argb) {
-  CFX_DIBitmap* pDib = (CFX_DIBitmap*)dib;
-  FXFT_Face face = pFont->GetFace();
-  int error = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_NO_BITMAP);
-  if (error) {
-    return FALSE;
-  }
-  error = FXFT_Render_Glyph(face, FXFT_RENDER_MODE_NORMAL);
-  if (error) {
-    return FALSE;
-  }
-  int bmwidth = FXFT_Get_Bitmap_Width(FXFT_Get_Glyph_Bitmap(face));
-  int bmheight = FXFT_Get_Bitmap_Rows(FXFT_Get_Glyph_Bitmap(face));
-  int left = FXFT_Get_Glyph_BitmapLeft(face);
-  int top = FXFT_Get_Glyph_BitmapTop(face);
-  const uint8_t* src_buf =
-      (const uint8_t*)FXFT_Get_Bitmap_Buffer(FXFT_Get_Glyph_Bitmap(face));
-  int src_pitch = FXFT_Get_Bitmap_Pitch(FXFT_Get_Glyph_Bitmap(face));
-  CFX_DIBitmap mask;
-  mask.Create(bmwidth, bmheight, FXDIB_8bppMask);
-  uint8_t* dest_buf = mask.GetBuffer();
-  int dest_pitch = mask.GetPitch();
-  for (int row = 0; row < bmheight; row++) {
-    const uint8_t* src_scan = src_buf + row * src_pitch;
-    uint8_t* dest_scan = dest_buf + row * dest_pitch;
-    FXSYS_memcpy(dest_scan, src_scan, dest_pitch);
-  }
-  pDib->CompositeMask(x + left, y - top, bmwidth, bmheight, &mask, argb, 0, 0);
-  return TRUE;
-}
-FX_BOOL OutputText(void* dib,
-                   int x,
-                   int y,
-                   CFX_Font* pFont,
-                   double font_size,
-                   CFX_AffineMatrix* pText_matrix,
-                   unsigned short const* text,
-                   unsigned long argb) {
-  if (!pFont) {
-    return FALSE;
-  }
-  FXFT_Face face = pFont->GetFace();
-  FXFT_Select_Charmap(pFont->m_Face, FXFT_ENCODING_UNICODE);
-  if (pText_matrix) {
-    FXFT_Matrix ft_matrix;
-    ft_matrix.xx = (signed long)(pText_matrix->a / 64 * 65536);
-    ft_matrix.xy = (signed long)(pText_matrix->c / 64 * 65536);
-    ft_matrix.yx = (signed long)(pText_matrix->b / 64 * 65536);
-    ft_matrix.yy = (signed long)(pText_matrix->d / 64 * 65536);
-    FXFT_Set_Transform(face, &ft_matrix, 0);
-  }
-  FX_FLOAT x_pos = 0;
-  for (; *text != 0; text++) {
-    FX_WCHAR unicode = *text;
-    int glyph_index = FXFT_Get_Char_Index(pFont->m_Face, unicode);
-    if (glyph_index <= 0) {
-      continue;
-    }
-    int err = FXFT_Load_Glyph(
-        pFont->m_Face, glyph_index,
-        FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
-    if (err) {
-      continue;
-    }
-    int w = FXFT_Get_Glyph_HoriAdvance(pFont->m_Face);
-    int em = FXFT_Get_Face_UnitsPerEM(pFont->m_Face);
-    FX_FLOAT x1, y1;
-    pText_matrix->Transform(x_pos, 0, x1, y1);
-    _OutputGlyph(dib, (int)x1 + x, (int)-y1 + y, pFont, glyph_index, argb);
-    x_pos += (FX_FLOAT)w / em;
-  }
-  if (pText_matrix)
-    ResetTransform(face);
-  return TRUE;
-}
-FX_BOOL OutputGlyph(void* dib,
-                    int x,
-                    int y,
-                    CFX_Font* pFont,
-                    double font_size,
-                    CFX_AffineMatrix* pMatrix,
-                    unsigned long glyph_index,
-                    unsigned long argb) {
-  FXFT_Matrix ft_matrix;
-  if (pMatrix) {
-    ft_matrix.xx = (signed long)(pMatrix->a * font_size / 64 * 65536);
-    ft_matrix.xy = (signed long)(pMatrix->c * font_size / 64 * 65536);
-    ft_matrix.yx = (signed long)(pMatrix->b * font_size / 64 * 65536);
-    ft_matrix.yy = (signed long)(pMatrix->d * font_size / 64 * 65536);
-  } else {
-    ft_matrix.xx = (signed long)(font_size / 64 * 65536);
-    ft_matrix.xy = ft_matrix.yx = 0;
-    ft_matrix.yy = (signed long)(font_size / 64 * 65536);
-  }
-  ScopedFontTransform scoped_transform(pFont->m_Face, &ft_matrix);
-  FX_BOOL ret = _OutputGlyph(dib, x, y, pFont, glyph_index, argb);
-  return ret;
-}
 const CFX_PathData* CFX_FaceCache::LoadGlyphPath(CFX_Font* pFont,
                                                  FX_DWORD glyph_index,
                                                  int dest_width) {