| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2008, Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "platform/fonts/win/SkiaFontWin.h" | |
| 33 | |
| 34 #include "platform/fonts/SimpleFontData.h" | |
| 35 #include "platform/fonts/win/FontPlatformDataWin.h" | |
| 36 #include "platform/graphics/Gradient.h" | |
| 37 #include "platform/graphics/GraphicsContext.h" | |
| 38 #include "platform/graphics/Pattern.h" | |
| 39 #include "platform/transforms/AffineTransform.h" | |
| 40 #include "third_party/skia/include/core/SkCanvas.h" | |
| 41 #include "third_party/skia/include/core/SkDevice.h" | |
| 42 #include "third_party/skia/include/core/SkPaint.h" | |
| 43 #include "third_party/skia/include/core/SkShader.h" | |
| 44 #include "third_party/skia/include/core/SkTemplates.h" | |
| 45 #include "wtf/RefPtr.h" | |
| 46 | |
| 47 namespace WebCore { | |
| 48 | |
| 49 static void skiaDrawText(GraphicsContext* context, | |
| 50 const SkPoint& point, | |
| 51 const SkRect& textRect, | |
| 52 SkPaint* paint, | |
| 53 const WORD* glyphs, | |
| 54 const int* advances, | |
| 55 const GOFFSET* offsets, | |
| 56 unsigned numGlyphs) | |
| 57 { | |
| 58 // Reserve space for 64 SkPoints on the stack. If numGlyphs is larger, the a
rray | |
| 59 // will dynamically allocate it space for numGlyph glyphs. This is used to s
tore | |
| 60 // the computed x,y locations. In the case where offsets==null, then we use
it | |
| 61 // to store (twice as many) SkScalars for x[] | |
| 62 static const size_t kLocalGlyphMax = 64; | |
| 63 | |
| 64 SkScalar x = point.fX; | |
| 65 SkScalar y = point.fY; | |
| 66 if (offsets) { | |
| 67 SkAutoSTArray<kLocalGlyphMax, SkPoint> storage(numGlyphs); | |
| 68 SkPoint* pos = storage.get(); | |
| 69 for (unsigned i = 0; i < numGlyphs; i++) { | |
| 70 // GDI has dv go up, so we negate it | |
| 71 pos[i].set(x + SkIntToScalar(offsets[i].du), y + -SkIntToScalar(offs
ets[i].dv)); | |
| 72 x += SkIntToScalar(advances[i]); | |
| 73 } | |
| 74 context->drawPosText(glyphs, numGlyphs * sizeof(uint16_t), pos, textRect
, *paint); | |
| 75 } else { | |
| 76 SkAutoSTArray<kLocalGlyphMax * 2, SkScalar> storage(numGlyphs); | |
| 77 SkScalar* xpos = storage.get(); | |
| 78 for (unsigned i = 0; i < numGlyphs; i++) { | |
| 79 xpos[i] = x; | |
| 80 x += SkIntToScalar(advances[i]); | |
| 81 } | |
| 82 context->drawPosTextH(glyphs, numGlyphs * sizeof(uint16_t), xpos, y, tex
tRect, *paint); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 void paintSkiaText(GraphicsContext* context, | |
| 87 const FontPlatformData& data, | |
| 88 unsigned numGlyphs, | |
| 89 const WORD* glyphs, | |
| 90 const int* advances, | |
| 91 const GOFFSET* offsets, | |
| 92 const SkPoint& origin, | |
| 93 const SkRect& textRect) | |
| 94 { | |
| 95 TextDrawingModeFlags textMode = context->textDrawingMode(); | |
| 96 | |
| 97 // Filling (if necessary). This is the common case. | |
| 98 SkPaint paint; | |
| 99 context->setupPaintForFilling(&paint); | |
| 100 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
| 101 data.setupPaint(&paint, context); | |
| 102 | |
| 103 bool didFill = false; | |
| 104 | |
| 105 if ((textMode & TextModeFill) && (SkColorGetA(paint.getColor()) || paint.get
Looper())) { | |
| 106 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0]
, &offsets[0], numGlyphs); | |
| 107 didFill = true; | |
| 108 } | |
| 109 | |
| 110 // Stroking on top (if necessary). | |
| 111 if ((textMode & TextModeStroke) | |
| 112 && context->strokeStyle() != NoStroke | |
| 113 && context->strokeThickness() > 0) { | |
| 114 | |
| 115 paint.reset(); | |
| 116 context->setupPaintForStroking(&paint); | |
| 117 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
| 118 data.setupPaint(&paint, context); | |
| 119 | |
| 120 if (didFill) { | |
| 121 // If there is a shadow and we filled above, there will already be | |
| 122 // a shadow. We don't want to draw it again or it will be too dark | |
| 123 // and it will go on top of the fill. | |
| 124 // | |
| 125 // Note that this isn't strictly correct, since the stroke could be | |
| 126 // very thick and the shadow wouldn't account for this. The "right" | |
| 127 // thing would be to draw to a new layer and then draw that layer | |
| 128 // with a shadow. But this is a lot of extra work for something | |
| 129 // that isn't normally an issue. | |
| 130 paint.setLooper(0); | |
| 131 } | |
| 132 | |
| 133 skiaDrawText(context, origin, textRect, &paint, &glyphs[0], &advances[0]
, &offsets[0], numGlyphs); | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 } // namespace WebCore | |
| OLD | NEW |