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 "xfa/fgas/font/cfgas_gefont.h" | 7 #include "xfa/fgas/font/cfgas_gefont.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 return false; | 207 return false; |
208 | 208 |
209 m_pFont = pInternalFont.release(); | 209 m_pFont = pInternalFont.release(); |
210 m_bExternalFont = false; | 210 m_bExternalFont = false; |
211 return InitFont(); | 211 return InitFont(); |
212 } | 212 } |
213 | 213 |
214 bool CFGAS_GEFont::InitFont() { | 214 bool CFGAS_GEFont::InitFont() { |
215 if (!m_pFont) | 215 if (!m_pFont) |
216 return false; | 216 return false; |
| 217 |
217 if (!m_pFontEncoding) { | 218 if (!m_pFontEncoding) { |
218 m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont)); | 219 m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont)); |
219 if (!m_pFontEncoding) | 220 if (!m_pFontEncoding) |
220 return false; | 221 return false; |
221 } | 222 } |
222 if (!m_pCharWidthMap) { | 223 if (!m_pCharWidthMap) { |
223 m_pCharWidthMap = | 224 m_pCharWidthMap = |
224 pdfium::MakeUnique<CFX_DiscreteArrayTemplate<uint16_t>>(1024); | 225 pdfium::MakeUnique<CFX_DiscreteArrayTemplate<uint16_t>>(1024); |
225 } | 226 } |
226 if (!m_pRectArray) | 227 if (!m_pRectArray) |
227 m_pRectArray = pdfium::MakeUnique<CFX_MassArrayTemplate<CFX_Rect>>(16); | 228 m_pRectArray = pdfium::MakeUnique<CFX_MassArrayTemplate<CFX_Rect>>(16); |
228 if (!m_pBBoxMap) | |
229 m_pBBoxMap = pdfium::MakeUnique<CFX_MapPtrToPtr>(16); | |
230 | 229 |
| 230 m_BBoxMap.clear(); |
231 return true; | 231 return true; |
232 } | 232 } |
233 | 233 |
234 CFX_RetainPtr<CFGAS_GEFont> CFGAS_GEFont::Derive(uint32_t dwFontStyles, | 234 CFX_RetainPtr<CFGAS_GEFont> CFGAS_GEFont::Derive(uint32_t dwFontStyles, |
235 uint16_t wCodePage) { | 235 uint16_t wCodePage) { |
236 CFX_RetainPtr<CFGAS_GEFont> pFont(this); | 236 CFX_RetainPtr<CFGAS_GEFont> pFont(this); |
237 if (GetFontStyles() == dwFontStyles) | 237 if (GetFontStyles() == dwFontStyles) |
238 return pFont; | 238 return pFont; |
239 return pdfium::MakeRetain<CFGAS_GEFont>(pFont, dwFontStyles); | 239 return pdfium::MakeRetain<CFGAS_GEFont>(pFont, dwFontStyles); |
240 } | 240 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 CFX_Rect& bbox, | 315 CFX_Rect& bbox, |
316 bool bCharCode) { | 316 bool bCharCode) { |
317 return GetCharBBoxInternal(wUnicode, bbox, true, bCharCode); | 317 return GetCharBBoxInternal(wUnicode, bbox, true, bCharCode); |
318 } | 318 } |
319 | 319 |
320 bool CFGAS_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode, | 320 bool CFGAS_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode, |
321 CFX_Rect& bbox, | 321 CFX_Rect& bbox, |
322 bool bRecursive, | 322 bool bRecursive, |
323 bool bCharCode) { | 323 bool bCharCode) { |
324 ASSERT(m_pRectArray); | 324 ASSERT(m_pRectArray); |
325 ASSERT(m_pBBoxMap); | 325 CFX_Rect* pRect = nullptr; |
326 void* pRect = nullptr; | 326 auto it = m_BBoxMap.find(wUnicode); |
327 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) { | 327 if (it == m_BBoxMap.end()) { |
328 CFX_RetainPtr<CFGAS_GEFont> pFont; | 328 CFX_RetainPtr<CFGAS_GEFont> pFont; |
329 int32_t iGlyph = GetGlyphIndex(wUnicode, true, &pFont, bCharCode); | 329 int32_t iGlyph = GetGlyphIndex(wUnicode, true, &pFont, bCharCode); |
330 if (iGlyph != 0xFFFF && pFont) { | 330 if (iGlyph != 0xFFFF && pFont) { |
331 if (pFont.Get() == this) { | 331 if (pFont.Get() == this) { |
332 FX_RECT rtBBox; | 332 FX_RECT rtBBox; |
333 if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) { | 333 if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) { |
334 CFX_Rect rt; | 334 CFX_Rect rt; |
335 rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height()); | 335 rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height()); |
336 int32_t index = m_pRectArray->Add(rt); | 336 int32_t index = m_pRectArray->Add(rt); |
337 pRect = m_pRectArray->GetPtrAt(index); | 337 pRect = m_pRectArray->GetPtrAt(index); |
338 m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect); | 338 m_BBoxMap[wUnicode] = pRect; |
339 } | 339 } |
340 } else if (pFont->GetCharBBoxInternal(wUnicode, bbox, false, bCharCode)) { | 340 } else if (pFont->GetCharBBoxInternal(wUnicode, bbox, false, bCharCode)) { |
341 return true; | 341 return true; |
342 } | 342 } |
343 } | 343 } |
| 344 } else { |
| 345 pRect = it->second; |
344 } | 346 } |
345 if (!pRect) | 347 if (!pRect) |
346 return false; | 348 return false; |
347 | 349 |
348 bbox = *static_cast<const CFX_Rect*>(pRect); | 350 bbox = *pRect; |
349 return true; | 351 return true; |
350 } | 352 } |
351 | 353 |
352 bool CFGAS_GEFont::GetBBox(CFX_Rect& bbox) { | 354 bool CFGAS_GEFont::GetBBox(CFX_Rect& bbox) { |
353 FX_RECT rt(0, 0, 0, 0); | 355 FX_RECT rt(0, 0, 0, 0); |
354 if (!m_pFont->GetBBox(rt)) | 356 if (!m_pFont->GetBBox(rt)) |
355 return false; | 357 return false; |
356 bbox.left = rt.left; | 358 bbox.left = rt.left; |
357 bbox.width = rt.Width(); | 359 bbox.width = rt.Width(); |
358 bbox.top = rt.bottom; | 360 bbox.top = rt.bottom; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 return m_pFont->GetDescent(); | 430 return m_pFont->GetDescent(); |
429 } | 431 } |
430 | 432 |
431 CFX_RetainPtr<CFGAS_GEFont> CFGAS_GEFont::GetSubstFont( | 433 CFX_RetainPtr<CFGAS_GEFont> CFGAS_GEFont::GetSubstFont( |
432 int32_t iGlyphIndex) const { | 434 int32_t iGlyphIndex) const { |
433 iGlyphIndex = static_cast<uint32_t>(iGlyphIndex) >> 24; | 435 iGlyphIndex = static_cast<uint32_t>(iGlyphIndex) >> 24; |
434 if (iGlyphIndex == 0) | 436 if (iGlyphIndex == 0) |
435 return CFX_RetainPtr<CFGAS_GEFont>(const_cast<CFGAS_GEFont*>(this)); | 437 return CFX_RetainPtr<CFGAS_GEFont>(const_cast<CFGAS_GEFont*>(this)); |
436 return m_SubstFonts[iGlyphIndex - 1]; | 438 return m_SubstFonts[iGlyphIndex - 1]; |
437 } | 439 } |
OLD | NEW |