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

Side by Side Diff: Source/platform/fonts/shaping/SimpleShaper.cpp

Issue 824263003: At some places Blink is using old style character string notation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2008 Holger Hans Peter Freyther 3 * Copyright (C) 2008 Holger Hans Peter Freyther
4 * Copyright (C) 2014 Google Inc. All rights reserved. 4 * Copyright (C) 2014 Google Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 12 matching lines...) Expand all
23 #include "config.h" 23 #include "config.h"
24 #include "platform/fonts/shaping/SimpleShaper.h" 24 #include "platform/fonts/shaping/SimpleShaper.h"
25 25
26 #include "platform/fonts/Character.h" 26 #include "platform/fonts/Character.h"
27 #include "platform/fonts/Font.h" 27 #include "platform/fonts/Font.h"
28 #include "platform/fonts/GlyphBuffer.h" 28 #include "platform/fonts/GlyphBuffer.h"
29 #include "platform/fonts/Latin1TextIterator.h" 29 #include "platform/fonts/Latin1TextIterator.h"
30 #include "platform/fonts/SimpleFontData.h" 30 #include "platform/fonts/SimpleFontData.h"
31 #include "platform/text/SurrogatePairAwareTextIterator.h" 31 #include "platform/text/SurrogatePairAwareTextIterator.h"
32 #include "wtf/MathExtras.h" 32 #include "wtf/MathExtras.h"
33 #include "wtf/unicode/CharacterNames.h"
33 34
34 using namespace WTF; 35 using namespace WTF;
35 using namespace Unicode; 36 using namespace Unicode;
36 37
37 namespace blink { 38 namespace blink {
38 39
39 SimpleShaper::SimpleShaper(const Font* font, const TextRun& run, 40 SimpleShaper::SimpleShaper(const Font* font, const TextRun& run,
40 HashSet<const SimpleFontData*>* fallbackFonts, GlyphBounds* bounds, 41 HashSet<const SimpleFontData*>* fallbackFonts, GlyphBounds* bounds,
41 bool forTextEmphasis) 42 bool forTextEmphasis)
42 : m_font(font) 43 : m_font(font)
(...skipping 27 matching lines...) Expand all
70 { 71 {
71 ASSERT(m_font); 72 ASSERT(m_font);
72 return m_font->glyphDataForCharacter(charData.character, m_run.rtl(), normal izeSpace); 73 return m_font->glyphDataForCharacter(charData.character, m_run.rtl(), normal izeSpace);
73 } 74 }
74 75
75 float SimpleShaper::characterWidth(UChar32 character, const GlyphData& glyphData ) const 76 float SimpleShaper::characterWidth(UChar32 character, const GlyphData& glyphData ) const
76 { 77 {
77 const SimpleFontData* fontData = glyphData.fontData; 78 const SimpleFontData* fontData = glyphData.fontData;
78 ASSERT(fontData); 79 ASSERT(fontData);
79 80
80 if (UNLIKELY(character == '\t' && m_run.allowTabs())) 81 if (UNLIKELY(character == characterTabulation && m_run.allowTabs()))
81 return m_font->tabWidth(*fontData, m_run.tabSize(), m_run.xPos() + m_run WidthSoFar); 82 return m_font->tabWidth(*fontData, m_run.tabSize(), m_run.xPos() + m_run WidthSoFar);
82 83
83 float width = fontData->widthForGlyph(glyphData.glyph); 84 float width = fontData->widthForGlyph(glyphData.glyph);
84 85
85 // SVG uses horizontalGlyphStretch(), when textLength is used to stretch/squ eeze text. 86 // SVG uses horizontalGlyphStretch(), when textLength is used to stretch/squ eeze text.
86 if (UNLIKELY(m_run.horizontalGlyphStretch() != 1)) 87 if (UNLIKELY(m_run.horizontalGlyphStretch() != 1))
87 width *= m_run.horizontalGlyphStretch(); 88 width *= m_run.horizontalGlyphStretch();
88 89
89 return width; 90 return width;
90 } 91 }
91 92
92 void SimpleShaper::cacheFallbackFont(const SimpleFontData* fontData, 93 void SimpleShaper::cacheFallbackFont(const SimpleFontData* fontData,
93 const SimpleFontData* primaryFont) 94 const SimpleFontData* primaryFont)
94 { 95 {
95 if (fontData == primaryFont) 96 if (fontData == primaryFont)
96 return; 97 return;
97 98
98 m_fallbackFonts->add(fontData); 99 m_fallbackFonts->add(fontData);
99 } 100 }
100 101
101 float SimpleShaper::adjustSpacing(float width, const CharacterData& charData) 102 float SimpleShaper::adjustSpacing(float width, const CharacterData& charData)
102 { 103 {
103 // Account for letter-spacing. 104 // Account for letter-spacing.
104 if (width) 105 if (width)
105 width += m_font->fontDescription().letterSpacing(); 106 width += m_font->fontDescription().letterSpacing();
106 107
107 bool isExpansionOpportunity = Character::treatAsSpace(charData.character) || (m_run.textJustify() == TextJustifyDistribute); 108 UChar32 character = charData.character;
eae 2014/12/30 16:29:11 This isn't really needed.
h.joshi 2015/01/04 16:22:35 Okey, removed these changes from new patch.
108 if (isExpansionOpportunity || (m_run.textJustify() == TextJustifyAuto && Cha racter::isCJKIdeographOrSymbol(charData.character))) { 109 bool isExpansionOpportunity = Character::treatAsSpace(character) || (m_run.t extJustify() == TextJustifyDistribute);
110 if (isExpansionOpportunity || (m_run.textJustify() == TextJustifyAuto && Cha racter::isCJKIdeographOrSymbol(character))) {
109 // Distribute the run's total expansion evenly over all expansion opport unities in the run. 111 // Distribute the run's total expansion evenly over all expansion opport unities in the run.
110 if (m_expansion) { 112 if (m_expansion) {
111 if (!isExpansionOpportunity && !m_isAfterExpansion) { 113 if (!isExpansionOpportunity && !m_isAfterExpansion) {
112 // Take the expansion opportunity before this ideograph. 114 // Take the expansion opportunity before this ideograph.
113 m_expansion -= m_expansionPerOpportunity; 115 m_expansion -= m_expansionPerOpportunity;
114 m_runWidthSoFar += m_expansionPerOpportunity; 116 m_runWidthSoFar += m_expansionPerOpportunity;
115 } 117 }
116 if (m_run.allowsTrailingExpansion() 118 if (m_run.allowsTrailingExpansion()
117 || (m_run.ltr() && charData.characterOffset + charData.clusterLe ngth < static_cast<size_t>(m_run.length())) 119 || (m_run.ltr() && charData.characterOffset + charData.clusterLe ngth < static_cast<size_t>(m_run.length()))
118 || (m_run.rtl() && charData.characterOffset)) { 120 || (m_run.rtl() && charData.characterOffset)) {
119 m_expansion -= m_expansionPerOpportunity; 121 m_expansion -= m_expansionPerOpportunity;
120 width += m_expansionPerOpportunity; 122 width += m_expansionPerOpportunity;
121 m_isAfterExpansion = true; 123 m_isAfterExpansion = true;
122 } 124 }
123 } else { 125 } else {
124 m_isAfterExpansion = false; 126 m_isAfterExpansion = false;
125 } 127 }
126 128
127 // Account for word spacing. 129 // Account for word spacing.
128 // We apply additional space between "words" by adding width to the spac e character. 130 // We apply additional space between "words" by adding width to the spac e character.
129 if (isExpansionOpportunity && (charData.character != '\t' || !m_run.allo wTabs()) 131 if (isExpansionOpportunity && (character != characterTabulation || !m_ru n.allowTabs())
130 && (charData.characterOffset || charData.character == noBreakSpace) 132 && (charData.characterOffset || character == noBreakSpace)
131 && m_font->fontDescription().wordSpacing()) { 133 && m_font->fontDescription().wordSpacing()) {
132 width += m_font->fontDescription().wordSpacing(); 134 width += m_font->fontDescription().wordSpacing();
133 } 135 }
134 } else { 136 } else {
135 m_isAfterExpansion = false; 137 m_isAfterExpansion = false;
136 } 138 }
137 139
138 return width; 140 return width;
139 } 141 }
140 142
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 float initialWidth = m_runWidthSoFar; 244 float initialWidth = m_runWidthSoFar;
243 245
244 if (!advance(m_currentCharacter + 1)) 246 if (!advance(m_currentCharacter + 1))
245 return false; 247 return false;
246 248
247 width = m_runWidthSoFar - initialWidth; 249 width = m_runWidthSoFar - initialWidth;
248 return true; 250 return true;
249 } 251 }
250 252
251 } // namespace blink 253 } // namespace blink
OLDNEW
« Source/platform/fonts/Font.cpp ('K') | « Source/platform/fonts/Font.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698