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

Side by Side Diff: third_party/WebKit/WebCore/platform/graphics/chromium/FontChromiumWin.cpp

Issue 18339: Attempt at getting GDI text to render when drawn using canvas. I added... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | third_party/WebKit/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 void Font::drawGlyphs(GraphicsContext* graphicsContext, 168 void Font::drawGlyphs(GraphicsContext* graphicsContext,
169 const SimpleFontData* font, 169 const SimpleFontData* font,
170 const GlyphBuffer& glyphBuffer, 170 const GlyphBuffer& glyphBuffer,
171 int from, 171 int from,
172 int numGlyphs, 172 int numGlyphs,
173 const FloatPoint& point) const 173 const FloatPoint& point) const
174 { 174 {
175 PlatformGraphicsContext* context = graphicsContext->platformContext(); 175 PlatformGraphicsContext* context = graphicsContext->platformContext();
176 176
177 bool canUseGDI = windowsCanHandleTextDrawing(graphicsContext);
178 bool createdLayer = false;
179
180 if (canUseGDI && context->isDrawingToImageBuffer()) {
181 // We're drawing to an image buffer and about to render text with GDI.
182 // We need to start a layer here, otherwise the alpha values rendered
183 // by GDI are never correctly updated.
184 // NOTE: this doesn't handle clear type well and should be removed when
185 // we have better text handling code.
186 graphicsContext->beginTransparencyLayer(1.0);
187 createdLayer = true;
188 }
189
177 // Max buffer length passed to the underlying windows API. 190 // Max buffer length passed to the underlying windows API.
178 const int kMaxBufferLength = 1024; 191 const int kMaxBufferLength = 1024;
179 // Default size for the buffer. It should be enough for most of cases. 192 // Default size for the buffer. It should be enough for most of cases.
180 const int kDefaultBufferLength = 256; 193 const int kDefaultBufferLength = 256;
181 194
182 SkColor color = context->fillColor(); 195 SkColor color = context->fillColor();
183 unsigned char alpha = SkColorGetA(color); 196 unsigned char alpha = SkColorGetA(color);
184 // Skip 100% transparent text; no need to draw anything. 197 // Skip 100% transparent text; no need to draw anything.
185 if (!alpha && context->getStrokeStyle() == NoStroke) 198 if (!alpha && context->getStrokeStyle() == NoStroke)
186 return; 199 return;
(...skipping 11 matching lines...) Expand all
198 // Windows needs the characters and the advances in nice contiguous 211 // Windows needs the characters and the advances in nice contiguous
199 // buffers, which we build here. 212 // buffers, which we build here.
200 Vector<WORD, kDefaultBufferLength> glyphs; 213 Vector<WORD, kDefaultBufferLength> glyphs;
201 Vector<int, kDefaultBufferLength> advances; 214 Vector<int, kDefaultBufferLength> advances;
202 215
203 // Compute the coordinate. The 'origin' represents the baseline, so we need 216 // Compute the coordinate. The 'origin' represents the baseline, so we need
204 // to move it up to the top of the bounding square. 217 // to move it up to the top of the bounding square.
205 int x = static_cast<int>(point.x()); 218 int x = static_cast<int>(point.x());
206 int lineTop = static_cast<int>(point.y()) - font->ascent(); 219 int lineTop = static_cast<int>(point.y()) - font->ascent();
207 220
208 bool canUseGDI = windowsCanHandleTextDrawing(graphicsContext);
209
210 // We draw the glyphs in chunks to avoid having to do a heap allocation for 221 // We draw the glyphs in chunks to avoid having to do a heap allocation for
211 // the arrays of characters and advances. Since ExtTextOut is the 222 // the arrays of characters and advances. Since ExtTextOut is the
212 // lowest-level text output function on Windows, there should be little 223 // lowest-level text output function on Windows, there should be little
213 // penalty for splitting up the text. On the other hand, the buffer cannot 224 // penalty for splitting up the text. On the other hand, the buffer cannot
214 // be bigger than 4094 or the function will fail. 225 // be bigger than 4094 or the function will fail.
215 int glyphIndex = 0; 226 int glyphIndex = 0;
216 while (glyphIndex < numGlyphs) { 227 while (glyphIndex < numGlyphs) {
217 // how many chars will be in this chunk? 228 // how many chars will be in this chunk?
218 int curLen = std::min(kMaxBufferLength, numGlyphs - glyphIndex); 229 int curLen = std::min(kMaxBufferLength, numGlyphs - glyphIndex);
219 230
(...skipping 25 matching lines...) Expand all
245 } 256 }
246 break; 257 break;
247 } 258 }
248 259
249 ASSERT(success); 260 ASSERT(success);
250 261
251 x += curWidth; 262 x += curWidth;
252 } 263 }
253 264
254 SelectObject(hdc, oldFont); 265 SelectObject(hdc, oldFont);
266 if (createdLayer)
267 graphicsContext->endTransparencyLayer();
255 context->canvas()->endPlatformPaint(); 268 context->canvas()->endPlatformPaint();
256 } 269 }
257 270
258 FloatRect Font::selectionRectForComplexText(const TextRun& run, 271 FloatRect Font::selectionRectForComplexText(const TextRun& run,
259 const IntPoint& point, 272 const IntPoint& point,
260 int h, 273 int h,
261 int from, 274 int from,
262 int to) const 275 int to) const
263 { 276 {
264 UniscribeHelperTextRun state(run, *this); 277 UniscribeHelperTextRun state(run, *this);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 int charIndex = state.xToCharacter(x); 331 int charIndex = state.xToCharacter(x);
319 332
320 // XToCharacter will return -1 if the position is before the first 333 // XToCharacter will return -1 if the position is before the first
321 // character (we get called like this sometimes). 334 // character (we get called like this sometimes).
322 if (charIndex < 0) 335 if (charIndex < 0)
323 charIndex = 0; 336 charIndex = 0;
324 return charIndex; 337 return charIndex;
325 } 338 }
326 339
327 } // namespace WebCore 340 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698