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

Side by Side Diff: Source/core/platform/graphics/chromium/FontChromiumWin.cpp

Issue 14160005: Track the region where text is painted. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase with TOT Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007 Apple Computer, Inc. 2 * Copyright (C) 2006, 2007 Apple Computer, Inc.
3 * Copyright (c) 2006, 2007, 2008, 2009, Google Inc. All rights reserved. 3 * Copyright (c) 2006, 2007, 2008, 2009, Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 bool Font::canExpandAroundIdeographsInComplexText() 55 bool Font::canExpandAroundIdeographsInComplexText()
56 { 56 {
57 return false; 57 return false;
58 } 58 }
59 59
60 void Font::drawGlyphs(GraphicsContext* graphicsContext, 60 void Font::drawGlyphs(GraphicsContext* graphicsContext,
61 const SimpleFontData* font, 61 const SimpleFontData* font,
62 const GlyphBuffer& glyphBuffer, 62 const GlyphBuffer& glyphBuffer,
63 int from, 63 int from,
64 int numGlyphs, 64 int numGlyphs,
65 const FloatPoint& point) const 65 const FloatPoint& point,
66 const FloatRect& textRect) const
66 { 67 {
67 SkColor color = graphicsContext->platformContext()->effectiveFillColor(); 68 SkColor color = graphicsContext->platformContext()->effectiveFillColor();
68 unsigned char alpha = SkColorGetA(color); 69 unsigned char alpha = SkColorGetA(color);
69 // Skip 100% transparent text; no need to draw anything. 70 // Skip 100% transparent text; no need to draw anything.
70 if (!alpha && graphicsContext->platformContext()->getStrokeStyle() == NoStro ke && !graphicsContext->hasShadow()) 71 if (!alpha && graphicsContext->platformContext()->getStrokeStyle() == NoStro ke && !graphicsContext->hasShadow())
71 return; 72 return;
72 73
73 // We draw the glyphs in chunks to avoid having to do a heap allocation for 74 // We draw the glyphs in chunks to avoid having to do a heap allocation for
74 // the arrays of characters and advances. 75 // the arrays of characters and advances.
75 const int kMaxBufferLength = 256; 76 const int kMaxBufferLength = 256;
76 Vector<int, kMaxBufferLength> advances; 77 Vector<int, kMaxBufferLength> advances;
77 int glyphIndex = 0; // The starting glyph of the current chunk. 78 int glyphIndex = 0; // The starting glyph of the current chunk.
78 79
79 float horizontalOffset = point.x(); // The floating point offset of the left side of the current glyph. 80 float horizontalOffset = point.x(); // The floating point offset of the left side of the current glyph.
81
80 #if ENABLE(OPENTYPE_VERTICAL) 82 #if ENABLE(OPENTYPE_VERTICAL)
81 const OpenTypeVerticalData* verticalData = font->verticalData(); 83 const OpenTypeVerticalData* verticalData = font->verticalData();
82 if (verticalData) { 84 if (verticalData) {
83 Vector<FloatPoint, kMaxBufferLength> translations; 85 Vector<FloatPoint, kMaxBufferLength> translations;
84 Vector<GOFFSET, kMaxBufferLength> offsets; 86 Vector<GOFFSET, kMaxBufferLength> offsets;
85 87
86 // Skia doesn't have matrix for glyph coordinate space, so we rotate bac k the CTM. 88 // Skia doesn't have matrix for glyph coordinate space, so we rotate bac k the CTM.
87 AffineTransform savedMatrix = graphicsContext->getCTM(); 89 AffineTransform savedMatrix = graphicsContext->getCTM();
88 graphicsContext->concatCTM(AffineTransform(0, -1, 1, 0, point.x(), point .y())); 90 graphicsContext->concatCTM(AffineTransform(0, -1, 1, 0, point.x(), point .y()));
89 graphicsContext->concatCTM(AffineTransform(1, 0, 0, 1, -point.x(), -poin t.y())); 91 graphicsContext->concatCTM(AffineTransform(1, 0, 0, 1, -point.x(), -poin t.y()));
(...skipping 13 matching lines...) Expand all
103 offsets.resize(curLen); 105 offsets.resize(curLen);
104 float currentWidth = 0; 106 float currentWidth = 0;
105 for (int i = 0; i < curLen; ++i, ++glyphIndex) { 107 for (int i = 0; i < curLen; ++i, ++glyphIndex) {
106 offsets[i].du = lroundf(translations[i].x()); 108 offsets[i].du = lroundf(translations[i].x());
107 offsets[i].dv = -lroundf(currentWidth - translations[i].y()); 109 offsets[i].dv = -lroundf(currentWidth - translations[i].y());
108 currentWidth += glyphBuffer.advanceAt(from + glyphIndex); 110 currentWidth += glyphBuffer.advanceAt(from + glyphIndex);
109 } 111 }
110 SkPoint origin; 112 SkPoint origin;
111 origin.set(verticalOriginX, SkFloatToScalar(point.y() + horizontalOf fset - point.x())); 113 origin.set(verticalOriginX, SkFloatToScalar(point.y() + horizontalOf fset - point.x()));
112 horizontalOffset += currentWidth; 114 horizontalOffset += currentWidth;
113 paintSkiaText(graphicsContext, font->platformData(), curLen, &glyphs [0], &advances[0], &offsets[0], &origin); 115 paintSkiaText(graphicsContext, font->platformData(), curLen, &glyphs [0], &advances[0], &offsets[0], origin, SkRect(textRect));
114 } 116 }
115 117
116 graphicsContext->setCTM(savedMatrix); 118 graphicsContext->setCTM(savedMatrix);
117 return; 119 return;
118 } 120 }
119 #endif 121 #endif
120 122
121 // In order to round all offsets to the correct pixel boundary, this code ke eps track of the absolute position 123 // In order to round all offsets to the correct pixel boundary, this code ke eps track of the absolute position
122 // of each glyph in floating point units and rounds to integer advances at t he last possible moment. 124 // of each glyph in floating point units and rounds to integer advances at t he last possible moment.
123 125
(...skipping 20 matching lines...) Expand all
144 // seems to crash if kMaxNegativeRun is set to somewhere around 146 // seems to crash if kMaxNegativeRun is set to somewhere around
145 // -32830, so we give ourselves a little breathing room. 147 // -32830, so we give ourselves a little breathing room.
146 const int maxNegativeRun = -32768; 148 const int maxNegativeRun = -32768;
147 const int maxPositiveRun = 32768; 149 const int maxPositiveRun = 32768;
148 if ((currentWidth + advances[i] < maxNegativeRun) || (currentWidth + advances[i] > maxPositiveRun)) 150 if ((currentWidth + advances[i] < maxNegativeRun) || (currentWidth + advances[i] > maxPositiveRun))
149 advances[i] = 0; 151 advances[i] = 0;
150 } 152 }
151 153
152 SkPoint origin = point; 154 SkPoint origin = point;
153 origin.fX += SkFloatToScalar(horizontalOffset - point.x() - currentWidth ); 155 origin.fX += SkFloatToScalar(horizontalOffset - point.x() - currentWidth );
154 paintSkiaText(graphicsContext, font->platformData(), curLen, &glyphs[0], &advances[0], 0, &origin); 156 paintSkiaText(graphicsContext, font->platformData(), curLen, &glyphs[0], &advances[0], 0, origin, SkRect(textRect));
155 } 157 }
156 } 158 }
157 159
158 FloatRect Font::selectionRectForComplexText(const TextRun& run, 160 FloatRect Font::selectionRectForComplexText(const TextRun& run,
159 const FloatPoint& point, 161 const FloatPoint& point,
160 int h, 162 int h,
161 int from, 163 int from,
162 int to) const 164 int to) const
163 { 165 {
164 UniscribeHelperTextRun state(run, *this); 166 UniscribeHelperTextRun state(run, *this);
165 float left = static_cast<float>(point.x() + state.characterToX(from)); 167 float left = static_cast<float>(point.x() + state.characterToX(from));
166 float right = static_cast<float>(point.x() + state.characterToX(to)); 168 float right = static_cast<float>(point.x() + state.characterToX(to));
167 169
168 // If the text is RTL, left will actually be after right. 170 // If the text is RTL, left will actually be after right.
169 if (left < right) 171 if (left < right)
170 return FloatRect(left, point.y(), 172 return FloatRect(left, point.y(),
171 right - left, static_cast<float>(h)); 173 right - left, static_cast<float>(h));
172 174
173 return FloatRect(right, point.y(), 175 return FloatRect(right, point.y(),
174 left - right, static_cast<float>(h)); 176 left - right, static_cast<float>(h));
175 } 177 }
176 178
177 void Font::drawComplexText(GraphicsContext* graphicsContext, 179 void Font::drawComplexText(GraphicsContext* graphicsContext,
178 const TextRun& run, 180 const TextRun& run,
179 const FloatPoint& point, 181 const FloatPoint& point,
182 const FloatRect& textRect,
180 int from, 183 int from,
181 int to) const 184 int to) const
182 { 185 {
183 PlatformGraphicsContext* context = graphicsContext->platformContext(); 186 PlatformGraphicsContext* context = graphicsContext->platformContext();
184 UniscribeHelperTextRun state(run, *this); 187 UniscribeHelperTextRun state(run, *this);
185 188
186 SkColor color = graphicsContext->platformContext()->effectiveFillColor(); 189 SkColor color = graphicsContext->platformContext()->effectiveFillColor();
187 unsigned char alpha = SkColorGetA(color); 190 unsigned char alpha = SkColorGetA(color);
188 // Skip 100% transparent text; no need to draw anything. 191 // Skip 100% transparent text; no need to draw anything.
189 if (!alpha && graphicsContext->platformContext()->getStrokeStyle() == NoStro ke) 192 if (!alpha && graphicsContext->platformContext()->getStrokeStyle() == NoStro ke)
190 return; 193 return;
191 194
192 HDC hdc = 0; 195 HDC hdc = 0;
193 // Uniscribe counts the coordinates from the upper left, while WebKit uses 196 // Uniscribe counts the coordinates from the upper left, while WebKit uses
194 // the baseline, so we have to subtract off the ascent. 197 // the baseline, so we have to subtract off the ascent.
195 state.draw(graphicsContext, hdc, lroundf(point.x()), lroundf(point.y() - fon tMetrics().ascent()), from, to); 198 state.draw(graphicsContext, hdc, lroundf(point.x()), lroundf(point.y() - fon tMetrics().ascent()), textRect, from, to);
196 } 199 }
197 200
198 void Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, int /* from */, int /* to */) const 201 void Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, const FloatRect& /* textRect */, int /* from */, int /* to */) const
199 { 202 {
200 notImplemented(); 203 notImplemented();
201 } 204 }
202 205
203 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon tData*>* /* fallbackFonts */, GlyphOverflow* /* glyphOverflow */) const 206 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon tData*>* /* fallbackFonts */, GlyphOverflow* /* glyphOverflow */) const
204 { 207 {
205 UniscribeHelperTextRun state(run, *this); 208 UniscribeHelperTextRun state(run, *this);
206 return static_cast<float>(state.width()); 209 return static_cast<float>(state.width());
207 } 210 }
208 211
(...skipping 10 matching lines...) Expand all
219 int charIndex = state.xToCharacter(x); 222 int charIndex = state.xToCharacter(x);
220 223
221 // XToCharacter will return -1 if the position is before the first 224 // XToCharacter will return -1 if the position is before the first
222 // character (we get called like this sometimes). 225 // character (we get called like this sometimes).
223 if (charIndex < 0) 226 if (charIndex < 0)
224 charIndex = 0; 227 charIndex = 0;
225 return charIndex; 228 return charIndex;
226 } 229 }
227 230
228 } // namespace WebCore 231 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698