| 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 <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "core/fxcodec/include/fx_codec.h" | 10 #include "core/fxcodec/include/fx_codec.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 rect.left = char_left.ValueOrDie(); | 100 rect.left = char_left.ValueOrDie(); |
| 101 rect.right = char_right.ValueOrDie(); | 101 rect.right = char_right.ValueOrDie(); |
| 102 rect.top = char_top.ValueOrDie(); | 102 rect.top = char_top.ValueOrDie(); |
| 103 rect.bottom = char_bottom.ValueOrDie(); | 103 rect.bottom = char_bottom.ValueOrDie(); |
| 104 bStarted = true; | 104 bStarted = true; |
| 105 } | 105 } |
| 106 return rect; | 106 return rect; |
| 107 } | 107 } |
| 108 | 108 |
| 109 CFX_FontCache::CFX_FontCache() {} | |
| 110 | |
| 111 CFX_FontCache::~CFX_FontCache() { | |
| 112 FreeCache(TRUE); | |
| 113 } | |
| 114 | |
| 115 CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) { | |
| 116 FXFT_Face internal_face = pFont->GetFace(); | |
| 117 const bool bExternal = !internal_face; | |
| 118 FXFT_Face face = | |
| 119 bExternal ? (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face; | |
| 120 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; | |
| 121 auto it = map.find(face); | |
| 122 if (it != map.end()) { | |
| 123 CFX_CountedFaceCache* counted_face_cache = it->second; | |
| 124 counted_face_cache->m_nCount++; | |
| 125 return counted_face_cache->m_Obj; | |
| 126 } | |
| 127 | |
| 128 CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face); | |
| 129 CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache; | |
| 130 counted_face_cache->m_nCount = 2; | |
| 131 counted_face_cache->m_Obj = face_cache; | |
| 132 map[face] = counted_face_cache; | |
| 133 return face_cache; | |
| 134 } | |
| 135 | |
| 136 #ifdef _SKIA_SUPPORT_ | |
| 137 CFX_TypeFace* CFX_FontCache::GetDeviceCache(CFX_Font* pFont) { | |
| 138 return GetCachedFace(pFont)->GetDeviceCache(pFont); | |
| 139 } | |
| 140 | |
| 141 CFX_TypeFace* CFX_FaceCache::GetDeviceCache(CFX_Font* pFont) { | |
| 142 if (!m_pTypeface) { | |
| 143 m_pTypeface = | |
| 144 SkTypeface::MakeFromStream( | |
| 145 new SkMemoryStream(pFont->GetFontData(), pFont->GetSize())) | |
| 146 .release(); | |
| 147 } | |
| 148 return m_pTypeface; | |
| 149 } | |
| 150 #endif | |
| 151 | |
| 152 void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) { | |
| 153 FXFT_Face internal_face = pFont->GetFace(); | |
| 154 const bool bExternal = !internal_face; | |
| 155 FXFT_Face face = | |
| 156 bExternal ? (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face; | |
| 157 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; | |
| 158 | |
| 159 auto it = map.find(face); | |
| 160 if (it == map.end()) | |
| 161 return; | |
| 162 | |
| 163 CFX_CountedFaceCache* counted_face_cache = it->second; | |
| 164 if (counted_face_cache->m_nCount > 1) { | |
| 165 counted_face_cache->m_nCount--; | |
| 166 } | |
| 167 } | |
| 168 | |
| 169 void CFX_FontCache::FreeCache(FX_BOOL bRelease) { | |
| 170 for (auto it = m_FTFaceMap.begin(); it != m_FTFaceMap.end();) { | |
| 171 auto curr_it = it++; | |
| 172 CFX_CountedFaceCache* cache = curr_it->second; | |
| 173 if (bRelease || cache->m_nCount < 2) { | |
| 174 delete cache->m_Obj; | |
| 175 delete cache; | |
| 176 m_FTFaceMap.erase(curr_it); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 for (auto it = m_ExtFaceMap.begin(); it != m_ExtFaceMap.end();) { | |
| 181 auto curr_it = it++; | |
| 182 CFX_CountedFaceCache* cache = curr_it->second; | |
| 183 if (bRelease || cache->m_nCount < 2) { | |
| 184 delete cache->m_Obj; | |
| 185 delete cache; | |
| 186 m_ExtFaceMap.erase(curr_it); | |
| 187 } | |
| 188 } | |
| 189 } | |
| 190 | |
| 191 CFX_FaceCache::CFX_FaceCache(FXFT_Face face) | 109 CFX_FaceCache::CFX_FaceCache(FXFT_Face face) |
| 192 : m_Face(face) | 110 : m_Face(face) |
| 193 #ifdef _SKIA_SUPPORT_ | 111 #ifdef _SKIA_SUPPORT_ |
| 194 , | 112 , |
| 195 m_pTypeface(nullptr) | 113 m_pTypeface(nullptr) |
| 196 #endif | 114 #endif |
| 197 { | 115 { |
| 198 } | 116 } |
| 199 | 117 |
| 200 CFX_FaceCache::~CFX_FaceCache() { | 118 CFX_FaceCache::~CFX_FaceCache() { |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 void _CFX_UniqueKeyGen::Generate(int count, ...) { | 758 void _CFX_UniqueKeyGen::Generate(int count, ...) { |
| 841 va_list argList; | 759 va_list argList; |
| 842 va_start(argList, count); | 760 va_start(argList, count); |
| 843 for (int i = 0; i < count; i++) { | 761 for (int i = 0; i < count; i++) { |
| 844 int p = va_arg(argList, int); | 762 int p = va_arg(argList, int); |
| 845 ((uint32_t*)m_Key)[i] = p; | 763 ((uint32_t*)m_Key)[i] = p; |
| 846 } | 764 } |
| 847 va_end(argList); | 765 va_end(argList); |
| 848 m_KeyLen = count * sizeof(uint32_t); | 766 m_KeyLen = count * sizeof(uint32_t); |
| 849 } | 767 } |
| OLD | NEW |