| 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 "../../include/fpdfdoc/fpdf_doc.h" | 7 #include "../../include/fpdfdoc/fpdf_doc.h" |
| 8 #include "../../include/fpdfdoc/fpdf_vt.h" | 8 #include "../../include/fpdfdoc/fpdf_vt.h" |
| 9 #include "pdf_vt.h" | 9 #include "pdf_vt.h" |
| 10 #include "../../include/fpdfdoc/fpdf_ap.h" | 10 #include "../../include/fpdfdoc/fpdf_ap.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 CPVT_Provider::CPVT_Provider(IPVT_FontMap* pFontMap) : m_pFontMap(pFontMap) { | 127 CPVT_Provider::CPVT_Provider(IPVT_FontMap* pFontMap) : m_pFontMap(pFontMap) { |
| 128 ASSERT(m_pFontMap != NULL); | 128 ASSERT(m_pFontMap != NULL); |
| 129 } | 129 } |
| 130 CPVT_Provider::~CPVT_Provider() {} | 130 CPVT_Provider::~CPVT_Provider() {} |
| 131 int32_t CPVT_Provider::GetCharWidth(int32_t nFontIndex, | 131 int32_t CPVT_Provider::GetCharWidth(int32_t nFontIndex, |
| 132 FX_WORD word, | 132 FX_WORD word, |
| 133 int32_t nWordStyle) { | 133 int32_t nWordStyle) { |
| 134 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { | 134 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
| 135 FX_DWORD charcode = pPDFFont->CharCodeFromUnicode(word); | 135 FX_DWORD charcode = pPDFFont->CharCodeFromUnicode(word); |
| 136 if (charcode != -1) { | 136 if (charcode != CPDF_Font::kInvalidCharCode) { |
| 137 return pPDFFont->GetCharWidthF(charcode); | 137 return pPDFFont->GetCharWidthF(charcode); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 return 0; | 140 return 0; |
| 141 } | 141 } |
| 142 int32_t CPVT_Provider::GetTypeAscent(int32_t nFontIndex) { | 142 int32_t CPVT_Provider::GetTypeAscent(int32_t nFontIndex) { |
| 143 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { | 143 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
| 144 return pPDFFont->GetTypeAscent(); | 144 return pPDFFont->GetTypeAscent(); |
| 145 } | 145 } |
| 146 return 0; | 146 return 0; |
| 147 } | 147 } |
| 148 int32_t CPVT_Provider::GetTypeDescent(int32_t nFontIndex) { | 148 int32_t CPVT_Provider::GetTypeDescent(int32_t nFontIndex) { |
| 149 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { | 149 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
| 150 return pPDFFont->GetTypeDescent(); | 150 return pPDFFont->GetTypeDescent(); |
| 151 } | 151 } |
| 152 return 0; | 152 return 0; |
| 153 } | 153 } |
| 154 int32_t CPVT_Provider::GetWordFontIndex(FX_WORD word, | 154 int32_t CPVT_Provider::GetWordFontIndex(FX_WORD word, |
| 155 int32_t charset, | 155 int32_t charset, |
| 156 int32_t nFontIndex) { | 156 int32_t nFontIndex) { |
| 157 if (CPDF_Font* pDefFont = m_pFontMap->GetPDFFont(0)) { | 157 if (CPDF_Font* pDefFont = m_pFontMap->GetPDFFont(0)) { |
| 158 if (pDefFont->CharCodeFromUnicode(word) != -1) { | 158 if (pDefFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode) { |
| 159 return 0; | 159 return 0; |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 if (CPDF_Font* pSysFont = m_pFontMap->GetPDFFont(1)) | 162 if (CPDF_Font* pSysFont = m_pFontMap->GetPDFFont(1)) { |
| 163 if (pSysFont->CharCodeFromUnicode(word) != -1) { | 163 if (pSysFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode) { |
| 164 return 1; | 164 return 1; |
| 165 } | 165 } |
| 166 } |
| 166 return -1; | 167 return -1; |
| 167 } | 168 } |
| 168 FX_BOOL CPVT_Provider::IsLatinWord(FX_WORD word) { | 169 FX_BOOL CPVT_Provider::IsLatinWord(FX_WORD word) { |
| 169 if ((word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) || | 170 if ((word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) || |
| 170 word == 0x2D || word == 0x27) { | 171 word == 0x2D || word == 0x27) { |
| 171 return TRUE; | 172 return TRUE; |
| 172 } | 173 } |
| 173 return FALSE; | 174 return FALSE; |
| 174 } | 175 } |
| 175 int32_t CPVT_Provider::GetDefaultFontIndex() { | 176 int32_t CPVT_Provider::GetDefaultFontIndex() { |
| 176 return 0; | 177 return 0; |
| 177 } | 178 } |
| 179 |
| 178 static CFX_ByteString GetPDFWordString(IPVT_FontMap* pFontMap, | 180 static CFX_ByteString GetPDFWordString(IPVT_FontMap* pFontMap, |
| 179 int32_t nFontIndex, | 181 int32_t nFontIndex, |
| 180 FX_WORD Word, | 182 FX_WORD Word, |
| 181 FX_WORD SubWord) { | 183 FX_WORD SubWord) { |
| 182 CFX_ByteString sWord; | 184 CFX_ByteString sWord; |
| 183 if (SubWord > 0) { | 185 if (SubWord > 0) { |
| 184 sWord.Format("%c", SubWord); | 186 sWord.Format("%c", SubWord); |
| 185 } else { | 187 return sWord; |
| 186 if (pFontMap) { | 188 } |
| 187 if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) { | 189 |
| 188 if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 || | 190 if (!pFontMap) |
| 189 pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) { | 191 return sWord; |
| 190 sWord.Format("%c", Word); | 192 |
| 191 } else { | 193 if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) { |
| 192 FX_DWORD dwCharCode = pPDFFont->CharCodeFromUnicode(Word); | 194 if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 || |
| 193 if (dwCharCode != -1) { | 195 pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) { |
| 194 pPDFFont->AppendChar(sWord, dwCharCode); | 196 sWord.Format("%c", Word); |
| 195 } | 197 } else { |
| 196 } | 198 FX_DWORD dwCharCode = pPDFFont->CharCodeFromUnicode(Word); |
| 199 if (dwCharCode != CPDF_Font::kInvalidCharCode) { |
| 200 pPDFFont->AppendChar(sWord, dwCharCode); |
| 197 } | 201 } |
| 198 } | 202 } |
| 199 } | 203 } |
| 200 return sWord; | 204 return sWord; |
| 201 } | 205 } |
| 206 |
| 202 static CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) { | 207 static CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) { |
| 203 if (strWords.GetLength() > 0) { | 208 if (strWords.GetLength() > 0) { |
| 204 return PDF_EncodeString(strWords) + " Tj\n"; | 209 return PDF_EncodeString(strWords) + " Tj\n"; |
| 205 } | 210 } |
| 206 return ""; | 211 return ""; |
| 207 } | 212 } |
| 208 static CFX_ByteString GetFontSetString(IPVT_FontMap* pFontMap, | 213 static CFX_ByteString GetFontSetString(IPVT_FontMap* pFontMap, |
| 209 int32_t nFontIndex, | 214 int32_t nFontIndex, |
| 210 FX_FLOAT fFontSize) { | 215 FX_FLOAT fFontSize) { |
| 211 CFX_ByteTextBuf sRet; | 216 CFX_ByteTextBuf sRet; |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 << "\n"; | 931 << "\n"; |
| 927 break; | 932 break; |
| 928 case CT_CMYK: | 933 case CT_CMYK: |
| 929 sColorStream << color.fColor1 << " " << color.fColor2 << " " | 934 sColorStream << color.fColor1 << " " << color.fColor2 << " " |
| 930 << color.fColor3 << " " << color.fColor4 << " " | 935 << color.fColor3 << " " << color.fColor4 << " " |
| 931 << (bFillOrStroke ? "k" : "K") << "\n"; | 936 << (bFillOrStroke ? "k" : "K") << "\n"; |
| 932 break; | 937 break; |
| 933 } | 938 } |
| 934 return sColorStream.GetByteString(); | 939 return sColorStream.GetByteString(); |
| 935 } | 940 } |
| OLD | NEW |