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

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: fixed build on win and mac Created 7 years, 7 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->effectiveFillColor(); 68 SkColor color = graphicsContext->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->strokeStyleSkia() == NoStroke && !graphicsCon text->hasShadow()) 71 if (!alpha && graphicsContext->strokeStyleSkia() == NoStroke && !graphicsCon text->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 TextRunPaintInfo& runInfo,
179 const FloatPoint& point, 181 const FloatPoint& point) const
180 int from,
181 int to) const
182 { 182 {
183 UniscribeHelperTextRun state(run, *this); 183 UniscribeHelperTextRun state(runInfo.run, *this);
184 184
185 SkColor color = graphicsContext->effectiveFillColor(); 185 SkColor color = graphicsContext->effectiveFillColor();
186 unsigned char alpha = SkColorGetA(color); 186 unsigned char alpha = SkColorGetA(color);
187 // Skip 100% transparent text; no need to draw anything. 187 // Skip 100% transparent text; no need to draw anything.
188 if (!alpha && graphicsContext->strokeStyleSkia() == NoStroke) 188 if (!alpha && graphicsContext->strokeStyleSkia() == NoStroke)
189 return; 189 return;
190 190
191 HDC hdc = 0; 191 HDC hdc = 0;
192 // Uniscribe counts the coordinates from the upper left, while WebKit uses 192 // Uniscribe counts the coordinates from the upper left, while WebKit uses
193 // the baseline, so we have to subtract off the ascent. 193 // the baseline, so we have to subtract off the ascent.
194 state.draw(graphicsContext, hdc, lroundf(point.x()), lroundf(point.y() - fon tMetrics().ascent()), from, to); 194 state.draw(graphicsContext, hdc, lroundf(point.x()), lroundf(point.y() - fon tMetrics().ascent()), runInfo.bounds, runInfo.from, runInfo.to);
195 } 195 }
196 196
197 void Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, int /* from */, int /* to */) const 197 void Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRunPaintInfo& /* runInfo */, const AtomicString& /* mark */, const FloatPoi nt& /* point */) const
198 { 198 {
199 notImplemented(); 199 notImplemented();
200 } 200 }
201 201
202 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon tData*>* /* fallbackFonts */, GlyphOverflow* /* glyphOverflow */) const 202 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon tData*>* /* fallbackFonts */, GlyphOverflow* /* glyphOverflow */) const
203 { 203 {
204 UniscribeHelperTextRun state(run, *this); 204 UniscribeHelperTextRun state(run, *this);
205 return static_cast<float>(state.width()); 205 return static_cast<float>(state.width());
206 } 206 }
207 207
(...skipping 10 matching lines...) Expand all
218 int charIndex = state.xToCharacter(x); 218 int charIndex = state.xToCharacter(x);
219 219
220 // XToCharacter will return -1 if the position is before the first 220 // XToCharacter will return -1 if the position is before the first
221 // character (we get called like this sometimes). 221 // character (we get called like this sometimes).
222 if (charIndex < 0) 222 if (charIndex < 0)
223 charIndex = 0; 223 charIndex = 0;
224 return charIndex; 224 return charIndex;
225 } 225 }
226 226
227 } // namespace WebCore 227 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/TextRun.h ('k') | Source/core/platform/graphics/chromium/UniscribeHelper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698