OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/include/fxge/fx_ge.h" | 7 #include "core/include/fxge/fx_ge.h" |
8 #include "core/include/fxge/fx_freetype.h" | 8 #include "core/include/fxge/fx_freetype.h" |
9 #include "core/include/fxcodec/fx_codec.h" | 9 #include "core/include/fxcodec/fx_codec.h" |
10 #include "text_int.h" | 10 #include "text_int.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 bgra[1], bgra[0]); | 169 bgra[1], bgra[0]); |
170 bgra[3] = (alpha_flag >> 24) ? FXGETFLAG_ALPHA_FILL(alpha_flag) | 170 bgra[3] = (alpha_flag >> 24) ? FXGETFLAG_ALPHA_FILL(alpha_flag) |
171 : FXGETFLAG_ALPHA_STROKE(alpha_flag); | 171 : FXGETFLAG_ALPHA_STROKE(alpha_flag); |
172 argb = FXARGB_MAKE(bgra[3], bgra[2], bgra[1], bgra[0]); | 172 argb = FXARGB_MAKE(bgra[3], bgra[2], bgra[1], bgra[0]); |
173 } | 173 } |
174 FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars, | 174 FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars, |
175 const FXTEXT_CHARPOS* pCharPos, | 175 const FXTEXT_CHARPOS* pCharPos, |
176 CFX_Font* pFont, | 176 CFX_Font* pFont, |
177 CFX_FontCache* pCache, | 177 CFX_FontCache* pCache, |
178 FX_FLOAT font_size, | 178 FX_FLOAT font_size, |
179 const CFX_AffineMatrix* pText2Device, | 179 const CFX_Matrix* pText2Device, |
180 FX_DWORD fill_color, | 180 FX_DWORD fill_color, |
181 FX_DWORD text_flags, | 181 FX_DWORD text_flags, |
182 int alpha_flag, | 182 int alpha_flag, |
183 void* pIccTransform) { | 183 void* pIccTransform) { |
184 int nativetext_flags = text_flags; | 184 int nativetext_flags = text_flags; |
185 if (m_DeviceClass != FXDC_DISPLAY) { | 185 if (m_DeviceClass != FXDC_DISPLAY) { |
186 if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) { | 186 if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) { |
187 bool should_call_draw_device_text = true; | 187 bool should_call_draw_device_text = true; |
188 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 188 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
189 if ((text_flags & FXFONT_CIDFONT) || | 189 if ((text_flags & FXFONT_CIDFONT) || |
(...skipping 23 matching lines...) Expand all Loading... |
213 should_call_draw_device_text = false; | 213 should_call_draw_device_text = false; |
214 } | 214 } |
215 #endif | 215 #endif |
216 if (should_call_draw_device_text && | 216 if (should_call_draw_device_text && |
217 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, | 217 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, |
218 pText2Device, font_size, fill_color, | 218 pText2Device, font_size, fill_color, |
219 alpha_flag, pIccTransform)) { | 219 alpha_flag, pIccTransform)) { |
220 return TRUE; | 220 return TRUE; |
221 } | 221 } |
222 } | 222 } |
223 CFX_AffineMatrix char2device, deviceCtm, text2Device; | 223 CFX_Matrix char2device, deviceCtm, text2Device; |
224 if (pText2Device) { | 224 if (pText2Device) { |
225 char2device = *pText2Device; | 225 char2device = *pText2Device; |
226 text2Device = *pText2Device; | 226 text2Device = *pText2Device; |
227 } | 227 } |
228 char2device.Scale(font_size, -font_size); | 228 char2device.Scale(font_size, -font_size); |
229 if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f || | 229 if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f || |
230 ((m_DeviceClass == FXDC_PRINTER && !m_pDeviceDriver->IsPSPrintDriver()) && | 230 ((m_DeviceClass == FXDC_PRINTER && !m_pDeviceDriver->IsPSPrintDriver()) && |
231 !(text_flags & FXTEXT_PRINTIMAGETEXT))) { | 231 !(text_flags & FXTEXT_PRINTIMAGETEXT))) { |
232 if (pFont->GetFace() != NULL || | 232 if (pFont->GetFace() != NULL || |
233 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { | 233 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 265 } |
266 } | 266 } |
267 if (pCache == NULL) { | 267 if (pCache == NULL) { |
268 pCache = CFX_GEModule::Get()->GetFontCache(); | 268 pCache = CFX_GEModule::Get()->GetFontCache(); |
269 } | 269 } |
270 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); | 270 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); |
271 FX_FONTCACHE_DEFINE(pCache, pFont); | 271 FX_FONTCACHE_DEFINE(pCache, pFont); |
272 FXTEXT_GLYPHPOS* pGlyphAndPos = FX_Alloc(FXTEXT_GLYPHPOS, nChars); | 272 FXTEXT_GLYPHPOS* pGlyphAndPos = FX_Alloc(FXTEXT_GLYPHPOS, nChars); |
273 int iChar; | 273 int iChar; |
274 deviceCtm = char2device; | 274 deviceCtm = char2device; |
275 CFX_AffineMatrix matrixCTM = GetCTM(); | 275 CFX_Matrix matrixCTM = GetCTM(); |
276 FX_FLOAT scale_x = FXSYS_fabs(matrixCTM.a); | 276 FX_FLOAT scale_x = FXSYS_fabs(matrixCTM.a); |
277 FX_FLOAT scale_y = FXSYS_fabs(matrixCTM.d); | 277 FX_FLOAT scale_y = FXSYS_fabs(matrixCTM.d); |
278 deviceCtm.Concat(scale_x, 0, 0, scale_y, 0, 0); | 278 deviceCtm.Concat(scale_x, 0, 0, scale_y, 0, 0); |
279 text2Device.Concat(scale_x, 0, 0, scale_y, 0, 0); | 279 text2Device.Concat(scale_x, 0, 0, scale_y, 0, 0); |
280 for (iChar = 0; iChar < nChars; iChar++) { | 280 for (iChar = 0; iChar < nChars; iChar++) { |
281 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar]; | 281 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar]; |
282 const FXTEXT_CHARPOS& charpos = pCharPos[iChar]; | 282 const FXTEXT_CHARPOS& charpos = pCharPos[iChar]; |
283 glyph.m_fOriginX = charpos.m_OriginX; | 283 glyph.m_fOriginX = charpos.m_OriginX; |
284 glyph.m_fOriginY = charpos.m_OriginY; | 284 glyph.m_fOriginY = charpos.m_OriginY; |
285 text2Device.Transform(glyph.m_fOriginX, glyph.m_fOriginY); | 285 text2Device.Transform(glyph.m_fOriginX, glyph.m_fOriginY); |
286 if (anti_alias < FXFT_RENDER_MODE_LCD) { | 286 if (anti_alias < FXFT_RENDER_MODE_LCD) { |
287 glyph.m_OriginX = FXSYS_round(glyph.m_fOriginX); | 287 glyph.m_OriginX = FXSYS_round(glyph.m_fOriginX); |
288 } else { | 288 } else { |
289 glyph.m_OriginX = (int)FXSYS_floor(glyph.m_fOriginX); | 289 glyph.m_OriginX = (int)FXSYS_floor(glyph.m_fOriginX); |
290 } | 290 } |
291 glyph.m_OriginY = FXSYS_round(glyph.m_fOriginY); | 291 glyph.m_OriginY = FXSYS_round(glyph.m_fOriginY); |
292 if (charpos.m_bGlyphAdjust) { | 292 if (charpos.m_bGlyphAdjust) { |
293 CFX_AffineMatrix new_matrix( | 293 CFX_Matrix new_matrix( |
294 charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], | 294 charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], |
295 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); | 295 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); |
296 new_matrix.Concat(deviceCtm); | 296 new_matrix.Concat(deviceCtm); |
297 glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( | 297 glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( |
298 pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &new_matrix, | 298 pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &new_matrix, |
299 charpos.m_FontCharWidth, anti_alias, nativetext_flags); | 299 charpos.m_FontCharWidth, anti_alias, nativetext_flags); |
300 } else { | 300 } else { |
301 glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( | 301 glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( |
302 pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &deviceCtm, | 302 pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &deviceCtm, |
303 charpos.m_FontCharWidth, anti_alias, nativetext_flags); | 303 charpos.m_FontCharWidth, anti_alias, nativetext_flags); |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top); | 1101 SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top); |
1102 } | 1102 } |
1103 FX_Free(pGlyphAndPos); | 1103 FX_Free(pGlyphAndPos); |
1104 return TRUE; | 1104 return TRUE; |
1105 } | 1105 } |
1106 FX_BOOL CFX_RenderDevice::DrawTextPath(int nChars, | 1106 FX_BOOL CFX_RenderDevice::DrawTextPath(int nChars, |
1107 const FXTEXT_CHARPOS* pCharPos, | 1107 const FXTEXT_CHARPOS* pCharPos, |
1108 CFX_Font* pFont, | 1108 CFX_Font* pFont, |
1109 CFX_FontCache* pCache, | 1109 CFX_FontCache* pCache, |
1110 FX_FLOAT font_size, | 1110 FX_FLOAT font_size, |
1111 const CFX_AffineMatrix* pText2User, | 1111 const CFX_Matrix* pText2User, |
1112 const CFX_AffineMatrix* pUser2Device, | 1112 const CFX_Matrix* pUser2Device, |
1113 const CFX_GraphStateData* pGraphState, | 1113 const CFX_GraphStateData* pGraphState, |
1114 FX_DWORD fill_color, | 1114 FX_DWORD fill_color, |
1115 FX_ARGB stroke_color, | 1115 FX_ARGB stroke_color, |
1116 CFX_PathData* pClippingPath, | 1116 CFX_PathData* pClippingPath, |
1117 int nFlag, | 1117 int nFlag, |
1118 int alpha_flag, | 1118 int alpha_flag, |
1119 void* pIccTransform, | 1119 void* pIccTransform, |
1120 int blend_type) { | 1120 int blend_type) { |
1121 if (pCache == NULL) { | 1121 if (pCache == NULL) { |
1122 pCache = CFX_GEModule::Get()->GetFontCache(); | 1122 pCache = CFX_GEModule::Get()->GetFontCache(); |
1123 } | 1123 } |
1124 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); | 1124 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); |
1125 FX_FONTCACHE_DEFINE(pCache, pFont); | 1125 FX_FONTCACHE_DEFINE(pCache, pFont); |
1126 for (int iChar = 0; iChar < nChars; iChar++) { | 1126 for (int iChar = 0; iChar < nChars; iChar++) { |
1127 const FXTEXT_CHARPOS& charpos = pCharPos[iChar]; | 1127 const FXTEXT_CHARPOS& charpos = pCharPos[iChar]; |
1128 CFX_AffineMatrix matrix; | 1128 CFX_Matrix matrix; |
1129 if (charpos.m_bGlyphAdjust) | 1129 if (charpos.m_bGlyphAdjust) |
1130 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], | 1130 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], |
1131 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); | 1131 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); |
1132 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, | 1132 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, |
1133 charpos.m_OriginY); | 1133 charpos.m_OriginY); |
1134 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( | 1134 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( |
1135 pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth); | 1135 pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth); |
1136 if (pPath == NULL) { | 1136 if (pPath == NULL) { |
1137 continue; | 1137 continue; |
1138 } | 1138 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 m_PathMap.GetNextAssoc(pos, key1, (void*&)pPath); | 1245 m_PathMap.GetNextAssoc(pos, key1, (void*&)pPath); |
1246 delete pPath; | 1246 delete pPath; |
1247 } | 1247 } |
1248 m_PathMap.RemoveAll(); | 1248 m_PathMap.RemoveAll(); |
1249 } | 1249 } |
1250 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ | 1250 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ |
1251 void CFX_FaceCache::InitPlatform() {} | 1251 void CFX_FaceCache::InitPlatform() {} |
1252 #endif | 1252 #endif |
1253 CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap( | 1253 CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap( |
1254 CFX_Font* pFont, | 1254 CFX_Font* pFont, |
1255 const CFX_AffineMatrix* pMatrix, | 1255 const CFX_Matrix* pMatrix, |
1256 CFX_ByteStringC& FaceGlyphsKey, | 1256 CFX_ByteStringC& FaceGlyphsKey, |
1257 FX_DWORD glyph_index, | 1257 FX_DWORD glyph_index, |
1258 FX_BOOL bFontStyle, | 1258 FX_BOOL bFontStyle, |
1259 int dest_width, | 1259 int dest_width, |
1260 int anti_alias) { | 1260 int anti_alias) { |
1261 CFX_SizeGlyphCache* pSizeCache; | 1261 CFX_SizeGlyphCache* pSizeCache; |
1262 auto it = m_SizeMap.find(FaceGlyphsKey); | 1262 auto it = m_SizeMap.find(FaceGlyphsKey); |
1263 if (it == m_SizeMap.end()) { | 1263 if (it == m_SizeMap.end()) { |
1264 pSizeCache = new CFX_SizeGlyphCache; | 1264 pSizeCache = new CFX_SizeGlyphCache; |
1265 m_SizeMap[FaceGlyphsKey] = pSizeCache; | 1265 m_SizeMap[FaceGlyphsKey] = pSizeCache; |
1266 } else { | 1266 } else { |
1267 pSizeCache = it->second; | 1267 pSizeCache = it->second; |
1268 } | 1268 } |
1269 CFX_GlyphBitmap* pGlyphBitmap = NULL; | 1269 CFX_GlyphBitmap* pGlyphBitmap = NULL; |
1270 if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index, | 1270 if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index, |
1271 (void*&)pGlyphBitmap)) { | 1271 (void*&)pGlyphBitmap)) { |
1272 return pGlyphBitmap; | 1272 return pGlyphBitmap; |
1273 } | 1273 } |
1274 pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle, pMatrix, | 1274 pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle, pMatrix, |
1275 dest_width, anti_alias); | 1275 dest_width, anti_alias); |
1276 if (pGlyphBitmap == NULL) { | 1276 if (pGlyphBitmap == NULL) { |
1277 return NULL; | 1277 return NULL; |
1278 } | 1278 } |
1279 pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap); | 1279 pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap); |
1280 return pGlyphBitmap; | 1280 return pGlyphBitmap; |
1281 } | 1281 } |
1282 const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap( | 1282 const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(CFX_Font* pFont, |
1283 CFX_Font* pFont, | 1283 FX_DWORD glyph_index, |
1284 FX_DWORD glyph_index, | 1284 FX_BOOL bFontStyle, |
1285 FX_BOOL bFontStyle, | 1285 const CFX_Matrix* pMatrix, |
1286 const CFX_AffineMatrix* pMatrix, | 1286 int dest_width, |
1287 int dest_width, | 1287 int anti_alias, |
1288 int anti_alias, | 1288 int& text_flags) { |
1289 int& text_flags) { | |
1290 if (glyph_index == (FX_DWORD)-1) { | 1289 if (glyph_index == (FX_DWORD)-1) { |
1291 return NULL; | 1290 return NULL; |
1292 } | 1291 } |
1293 _CFX_UniqueKeyGen keygen; | 1292 _CFX_UniqueKeyGen keygen; |
1294 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ | 1293 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ |
1295 if (pFont->GetSubstFont()) | 1294 if (pFont->GetSubstFont()) |
1296 keygen.Generate(9, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000), | 1295 keygen.Generate(9, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000), |
1297 (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), | 1296 (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), |
1298 dest_width, anti_alias, pFont->GetSubstFont()->m_Weight, | 1297 dest_width, anti_alias, pFont->GetSubstFont()->m_Weight, |
1299 pFont->GetSubstFont()->m_ItalicAngle, pFont->IsVertical()); | 1298 pFont->GetSubstFont()->m_ItalicAngle, pFont->IsVertical()); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 } else if (temp < 0) { | 1510 } else if (temp < 0) { |
1512 temp = 0; | 1511 temp = 0; |
1513 } | 1512 } |
1514 *pDstRow++ = (uint8_t)temp; | 1513 *pDstRow++ = (uint8_t)temp; |
1515 } | 1514 } |
1516 } | 1515 } |
1517 } | 1516 } |
1518 CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont, | 1517 CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont, |
1519 FX_DWORD glyph_index, | 1518 FX_DWORD glyph_index, |
1520 FX_BOOL bFontStyle, | 1519 FX_BOOL bFontStyle, |
1521 const CFX_AffineMatrix* pMatrix, | 1520 const CFX_Matrix* pMatrix, |
1522 int dest_width, | 1521 int dest_width, |
1523 int anti_alias) { | 1522 int anti_alias) { |
1524 if (m_Face == NULL) { | 1523 if (m_Face == NULL) { |
1525 return NULL; | 1524 return NULL; |
1526 } | 1525 } |
1527 FXFT_Matrix ft_matrix; | 1526 FXFT_Matrix ft_matrix; |
1528 ft_matrix.xx = (signed long)(pMatrix->GetA() / 64 * 65536); | 1527 ft_matrix.xx = (signed long)(pMatrix->GetA() / 64 * 65536); |
1529 ft_matrix.xy = (signed long)(pMatrix->GetC() / 64 * 65536); | 1528 ft_matrix.xy = (signed long)(pMatrix->GetC() / 64 * 65536); |
1530 ft_matrix.yx = (signed long)(pMatrix->GetB() / 64 * 65536); | 1529 ft_matrix.yx = (signed long)(pMatrix->GetB() / 64 * 65536); |
1531 ft_matrix.yy = (signed long)(pMatrix->GetD() / 64 * 65536); | 1530 ft_matrix.yy = (signed long)(pMatrix->GetD() / 64 * 65536); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1873 void _CFX_UniqueKeyGen::Generate(int count, ...) { | 1872 void _CFX_UniqueKeyGen::Generate(int count, ...) { |
1874 va_list argList; | 1873 va_list argList; |
1875 va_start(argList, count); | 1874 va_start(argList, count); |
1876 for (int i = 0; i < count; i++) { | 1875 for (int i = 0; i < count; i++) { |
1877 int p = va_arg(argList, int); | 1876 int p = va_arg(argList, int); |
1878 ((FX_DWORD*)m_Key)[i] = p; | 1877 ((FX_DWORD*)m_Key)[i] = p; |
1879 } | 1878 } |
1880 va_end(argList); | 1879 va_end(argList); |
1881 m_KeyLen = count * sizeof(FX_DWORD); | 1880 m_KeyLen = count * sizeof(FX_DWORD); |
1882 } | 1881 } |
OLD | NEW |