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

Side by Side Diff: core/fxge/ge/cfx_facecache.cpp

Issue 2296193002: Use CheckedNumeric for strength calculation. (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | no next file » | 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/fxge/include/cfx_facecache.h" 7 #include "core/fxge/include/cfx_facecache.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 int weight = 0; 147 int weight = 0;
148 if (bUseCJKSubFont) 148 if (bUseCJKSubFont)
149 weight = pSubstFont->m_WeightCJK; 149 weight = pSubstFont->m_WeightCJK;
150 else 150 else
151 weight = pSubstFont ? pSubstFont->m_Weight : 0; 151 weight = pSubstFont ? pSubstFont->m_Weight : 0;
152 if (pSubstFont && !(pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && 152 if (pSubstFont && !(pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) &&
153 weight > 400) { 153 weight > 400) {
154 uint32_t index = (weight - 400) / 10; 154 uint32_t index = (weight - 400) / 10;
155 if (index >= CFX_Font::kWeightPowArraySize) 155 if (index >= CFX_Font::kWeightPowArraySize)
156 return nullptr; 156 return nullptr;
157 int level = 0; 157 FT_Pos level = 0;
Wei Li 2016/08/31 16:59:37 This may not work on some platform such as Windows
dsinclair 2016/08/31 18:19:41 Switched to CheckedNumeric.
158 if (pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) { 158 if (pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) {
159 level = 159 level = CFX_Font::s_WeightPow_SHIFTJIS[index] * 2 *
160 CFX_Font::s_WeightPow_SHIFTJIS[index] * 2 * 160 static_cast<FT_Pos>(FXSYS_abs(static_cast<int>(ft_matrix.xx)) +
161 (FXSYS_abs((int)(ft_matrix.xx)) + FXSYS_abs((int)(ft_matrix.xy))) / 161 FXSYS_abs(static_cast<int>(ft_matrix.xy))) /
162 36655; 162 36655;
163 } else { 163 } else {
164 level = 164 level = CFX_Font::s_WeightPow_11[index] *
165 CFX_Font::s_WeightPow_11[index] * 165 static_cast<FT_Pos>(FXSYS_abs(static_cast<int>(ft_matrix.xx)) +
Lei Zhang 2016/08/31 17:34:27 BTW, can we combine the similar portions of the if
dsinclair 2016/08/31 18:19:41 Done.
166 (FXSYS_abs((int)(ft_matrix.xx)) + FXSYS_abs((int)(ft_matrix.xy))) / 166 FXSYS_abs(static_cast<int>(ft_matrix.xy))) /
167 36655; 167 36655;
168 } 168 }
169 FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level); 169 FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level);
170 } 170 }
171 FXFT_Library_SetLcdFilter(CFX_GEModule::Get()->GetFontMgr()->GetFTLibrary(), 171 FXFT_Library_SetLcdFilter(CFX_GEModule::Get()->GetFontMgr()->GetFTLibrary(),
172 FT_LCD_FILTER_DEFAULT); 172 FT_LCD_FILTER_DEFAULT);
173 error = FXFT_Render_Glyph(m_Face, anti_alias); 173 error = FXFT_Render_Glyph(m_Face, anti_alias);
174 if (error) 174 if (error)
175 return nullptr; 175 return nullptr;
176 int bmwidth = FXFT_Get_Bitmap_Width(FXFT_Get_Glyph_Bitmap(m_Face)); 176 int bmwidth = FXFT_Get_Bitmap_Width(FXFT_Get_Glyph_Bitmap(m_Face));
177 int bmheight = FXFT_Get_Bitmap_Rows(FXFT_Get_Glyph_Bitmap(m_Face)); 177 int bmheight = FXFT_Get_Bitmap_Rows(FXFT_Get_Glyph_Bitmap(m_Face));
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 return it2->second; 375 return it2->second;
376 376
377 CFX_GlyphBitmap* pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle, 377 CFX_GlyphBitmap* pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle,
378 pMatrix, dest_width, anti_alias); 378 pMatrix, dest_width, anti_alias);
379 if (!pGlyphBitmap) 379 if (!pGlyphBitmap)
380 return nullptr; 380 return nullptr;
381 381
382 pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap; 382 pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap;
383 return pGlyphBitmap; 383 return pGlyphBitmap;
384 } 384 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698