Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: core/fpdfapi/fpdf_font/cpdf_simplefont.cpp

Issue 2248463002: Get rid of FX_SMALL_RECT. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@fontclean
Patch Set: nits Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/fpdf_font/cpdf_simplefont.h ('k') | core/fpdfapi/fpdf_font/font_int.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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/fpdfapi/fpdf_font/cpdf_simplefont.h" 7 #include "core/fpdfapi/fpdf_font/cpdf_simplefont.h"
8 8
9 #include "core/fpdfapi/fpdf_font/font_int.h" 9 #include "core/fpdfapi/fpdf_font/font_int.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
12 #include "core/fxge/include/fx_freetype.h" 12 #include "core/fxge/include/fx_freetype.h"
13 13
14 CPDF_SimpleFont::CPDF_SimpleFont() : m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) { 14 CPDF_SimpleFont::CPDF_SimpleFont() : m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) {
15 FXSYS_memset(m_CharWidth, 0xff, sizeof(m_CharWidth)); 15 FXSYS_memset(m_CharWidth, 0xff, sizeof(m_CharWidth));
16 FXSYS_memset(m_GlyphIndex, 0xff, sizeof(m_GlyphIndex)); 16 FXSYS_memset(m_GlyphIndex, 0xff, sizeof(m_GlyphIndex));
17 FXSYS_memset(m_ExtGID, 0xff, sizeof(m_ExtGID)); 17 FXSYS_memset(m_ExtGID, 0xff, sizeof(m_ExtGID));
18 for (size_t i = 0; i < FX_ArraySize(m_CharBBox); ++i)
19 m_CharBBox[i] = FX_RECT(-1, -1, -1, -1);
18 } 20 }
19 21
20 CPDF_SimpleFont::~CPDF_SimpleFont() {} 22 CPDF_SimpleFont::~CPDF_SimpleFont() {}
21 23
22 int CPDF_SimpleFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) { 24 int CPDF_SimpleFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) {
23 if (pVertGlyph) 25 if (pVertGlyph)
24 *pVertGlyph = false; 26 *pVertGlyph = false;
25 27
26 if (charcode > 0xff) 28 if (charcode > 0xff)
27 return -1; 29 return -1;
(...skipping 17 matching lines...) Expand all
45 if (m_bUseFontWidth) { 47 if (m_bUseFontWidth) {
46 m_CharWidth[charcode] = m_CharWidth[32]; 48 m_CharWidth[charcode] = m_CharWidth[32];
47 } 49 }
48 } 50 }
49 return; 51 return;
50 } 52 }
51 FXFT_Face face = m_Font.GetFace(); 53 FXFT_Face face = m_Font.GetFace();
52 int err = FXFT_Load_Glyph( 54 int err = FXFT_Load_Glyph(
53 face, glyph_index, 55 face, glyph_index,
54 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); 56 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
55 if (err) { 57 if (err)
56 return; 58 return;
57 } 59
58 m_CharBBox[charcode] = FX_SMALL_RECT( 60 int iHoriBearingX = FXFT_Get_Glyph_HoriBearingX(face);
59 TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face), 61 int iHoriBearingY = FXFT_Get_Glyph_HoriBearingY(face);
60 TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face), 62 m_CharBBox[charcode] =
61 TT2PDF(FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face), 63 FX_RECT(TT2PDF(iHoriBearingX, face), TT2PDF(iHoriBearingY, face),
62 face), 64 TT2PDF(iHoriBearingX + FXFT_Get_Glyph_Width(face), face),
63 TT2PDF(FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face), 65 TT2PDF(iHoriBearingY - FXFT_Get_Glyph_Height(face), face));
64 face));
65 66
66 if (m_bUseFontWidth) { 67 if (m_bUseFontWidth) {
67 int TT_Width = TT2PDF(FXFT_Get_Glyph_HoriAdvance(face), face); 68 int TT_Width = TT2PDF(FXFT_Get_Glyph_HoriAdvance(face), face);
68 if (m_CharWidth[charcode] == 0xffff) { 69 if (m_CharWidth[charcode] == 0xffff) {
69 m_CharWidth[charcode] = TT_Width; 70 m_CharWidth[charcode] = TT_Width;
70 } else if (TT_Width && !IsEmbedded()) { 71 } else if (TT_Width && !IsEmbedded()) {
71 m_CharBBox[charcode].right = 72 m_CharBBox[charcode].right =
72 m_CharBBox[charcode].right * m_CharWidth[charcode] / TT_Width; 73 m_CharBBox[charcode].right * m_CharWidth[charcode] / TT_Width;
73 m_CharBBox[charcode].left = 74 m_CharBBox[charcode].left =
74 m_CharBBox[charcode].left * m_CharWidth[charcode] / TT_Width; 75 m_CharBBox[charcode].left * m_CharWidth[charcode] / TT_Width;
75 } 76 }
76 } 77 }
77 } 78 }
78 79
79 int CPDF_SimpleFont::GetCharWidthF(uint32_t charcode, int level) { 80 int CPDF_SimpleFont::GetCharWidthF(uint32_t charcode, int level) {
80 if (charcode > 0xff) { 81 if (charcode > 0xff)
81 charcode = 0; 82 charcode = 0;
82 } 83
83 if (m_CharWidth[charcode] == 0xffff) { 84 if (m_CharWidth[charcode] == 0xffff) {
84 LoadCharMetrics(charcode); 85 LoadCharMetrics(charcode);
85 if (m_CharWidth[charcode] == 0xffff) { 86 if (m_CharWidth[charcode] == 0xffff) {
86 m_CharWidth[charcode] = 0; 87 m_CharWidth[charcode] = 0;
87 } 88 }
88 } 89 }
89 return (int16_t)m_CharWidth[charcode]; 90 return m_CharWidth[charcode];
90 } 91 }
91 92
92 FX_RECT CPDF_SimpleFont::GetCharBBox(uint32_t charcode, int level) { 93 FX_RECT CPDF_SimpleFont::GetCharBBox(uint32_t charcode, int level) {
93 if (charcode > 0xff) 94 if (charcode > 0xff)
94 charcode = 0; 95 charcode = 0;
95 96
96 if (m_CharBBox[charcode].left == FX_SMALL_RECT::kInvalid) 97 if (m_CharBBox[charcode].left == -1)
97 LoadCharMetrics(charcode); 98 LoadCharMetrics(charcode);
98 99
99 return FX_RECT(m_CharBBox[charcode]); 100 return m_CharBBox[charcode];
100 } 101 }
101 102
102 FX_BOOL CPDF_SimpleFont::LoadCommon() { 103 FX_BOOL CPDF_SimpleFont::LoadCommon() {
103 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictBy("FontDescriptor"); 104 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictBy("FontDescriptor");
104 if (pFontDesc) { 105 if (pFontDesc) {
105 LoadFontDescriptor(pFontDesc); 106 LoadFontDescriptor(pFontDesc);
106 } 107 }
107 CPDF_Array* pWidthArray = m_pFontDict->GetArrayBy("Widths"); 108 CPDF_Array* pWidthArray = m_pFontDict->GetArrayBy("Widths");
108 m_bUseFontWidth = TRUE; 109 m_bUseFontWidth = !pWidthArray;
109 if (pWidthArray) { 110 if (pWidthArray) {
110 m_bUseFontWidth = FALSE;
111 if (pFontDesc && pFontDesc->KeyExist("MissingWidth")) { 111 if (pFontDesc && pFontDesc->KeyExist("MissingWidth")) {
112 int MissingWidth = pFontDesc->GetIntegerBy("MissingWidth"); 112 int MissingWidth = pFontDesc->GetIntegerBy("MissingWidth");
113 for (int i = 0; i < 256; i++) { 113 for (int i = 0; i < 256; i++) {
114 m_CharWidth[i] = MissingWidth; 114 m_CharWidth[i] = MissingWidth;
115 } 115 }
116 } 116 }
117 size_t width_start = m_pFontDict->GetIntegerBy("FirstChar", 0); 117 size_t width_start = m_pFontDict->GetIntegerBy("FirstChar", 0);
118 size_t width_end = m_pFontDict->GetIntegerBy("LastChar", 0); 118 size_t width_end = m_pFontDict->GetIntegerBy("LastChar", 0);
119 if (width_start <= 255) { 119 if (width_start <= 255) {
120 if (width_end == 0 || width_end >= width_start + pWidthArray->GetCount()) 120 if (width_end == 0 || width_end >= width_start + pWidthArray->GetCount())
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 return CFX_WideString(); 201 return CFX_WideString();
202 return ret; 202 return ret;
203 } 203 }
204 204
205 uint32_t CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const { 205 uint32_t CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const {
206 uint32_t ret = CPDF_Font::CharCodeFromUnicode(unicode); 206 uint32_t ret = CPDF_Font::CharCodeFromUnicode(unicode);
207 if (ret) 207 if (ret)
208 return ret; 208 return ret;
209 return m_Encoding.CharCodeFromUnicode(unicode); 209 return m_Encoding.CharCodeFromUnicode(unicode);
210 } 210 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_font/cpdf_simplefont.h ('k') | core/fpdfapi/fpdf_font/font_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698