| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 return renderer->isText() ? renderer->parent() : renderer; | 63 return renderer->isText() ? renderer->parent() : renderer; |
| 64 } | 64 } |
| 65 | 65 |
| 66 static inline RenderObject* renderObjectFromRun(const TextRun& run) | 66 static inline RenderObject* renderObjectFromRun(const TextRun& run) |
| 67 { | 67 { |
| 68 if (TextRun::RenderingContext* renderingContext = run.renderingContext()) | 68 if (TextRun::RenderingContext* renderingContext = run.renderingContext()) |
| 69 return static_cast<SVGTextRunRenderingContext*>(renderingContext)->rende
rer(); | 69 return static_cast<SVGTextRunRenderingContext*>(renderingContext)->rende
rer(); |
| 70 return 0; | 70 return 0; |
| 71 } | 71 } |
| 72 | 72 |
| 73 static inline RenderSVGResource* activePaintingResourceFromRun(const TextRun& ru
n) | |
| 74 { | |
| 75 if (TextRun::RenderingContext* renderingContext = run.renderingContext()) | |
| 76 return static_cast<SVGTextRunRenderingContext*>(renderingContext)->activ
ePaintingResource(); | |
| 77 return 0; | |
| 78 } | |
| 79 | |
| 80 float SVGTextRunRenderingContext::floatWidthUsingSVGFont(const Font& font, const
TextRun& run, int& charsConsumed, Glyph& glyphId) const | 73 float SVGTextRunRenderingContext::floatWidthUsingSVGFont(const Font& font, const
TextRun& run, int& charsConsumed, Glyph& glyphId) const |
| 81 { | 74 { |
| 82 WidthIterator it(&font, run); | 75 WidthIterator it(&font, run); |
| 83 GlyphBuffer glyphBuffer; | 76 GlyphBuffer glyphBuffer; |
| 84 charsConsumed += it.advance(run.length(), &glyphBuffer); | 77 charsConsumed += it.advance(run.length(), &glyphBuffer); |
| 85 glyphId = !glyphBuffer.isEmpty() ? glyphBuffer.glyphAt(0) : 0; | 78 glyphId = !glyphBuffer.isEmpty() ? glyphBuffer.glyphAt(0) : 0; |
| 86 return it.runWidthSoFar(); | 79 return it.runWidthSoFar(); |
| 87 } | 80 } |
| 88 | 81 |
| 89 void SVGTextRunRenderingContext::drawSVGGlyphs(GraphicsContext* context, const T
extRun& run, const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int
from, int numGlyphs, const FloatPoint& point) const | 82 void SVGTextRunRenderingContext::drawSVGGlyphs(GraphicsContext* context, const T
extRun& run, const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int
from, int numGlyphs, const FloatPoint& point) const |
| 90 { | 83 { |
| 91 SVGFontElement* fontElement = 0; | 84 SVGFontElement* fontElement = 0; |
| 92 SVGFontFaceElement* fontFaceElement = 0; | 85 SVGFontFaceElement* fontFaceElement = 0; |
| 93 | 86 |
| 94 const SVGFontData* svgFontData = svgFontAndFontFaceElementForFontData(fontDa
ta, fontFaceElement, fontElement); | 87 const SVGFontData* svgFontData = svgFontAndFontFaceElementForFontData(fontDa
ta, fontFaceElement, fontElement); |
| 95 if (!fontElement || !fontFaceElement) | 88 if (!fontElement || !fontFaceElement) |
| 96 return; | 89 return; |
| 97 | 90 |
| 98 // We can only paint SVGFonts if a context is available. | 91 // We can only paint SVGFonts if a context is available. |
| 99 RenderSVGResource* activePaintingResource = activePaintingResourceFromRun(ru
n); | |
| 100 RenderObject* renderObject = renderObjectFromRun(run); | 92 RenderObject* renderObject = renderObjectFromRun(run); |
| 101 RenderObject* parentRenderObject = firstParentRendererForNonTextNode(renderO
bject); | |
| 102 RenderStyle* parentRenderObjectStyle = 0; | |
| 103 | |
| 104 ASSERT(renderObject); | 93 ASSERT(renderObject); |
| 105 if (!activePaintingResource) { | |
| 106 // TODO: We're only supporting simple filled HTML text so far. | |
| 107 RenderSVGResourceSolidColor* solidPaintingResource = RenderSVGResource::
sharedSolidPaintingResource(); | |
| 108 solidPaintingResource->setColor(context->fillColor()); | |
| 109 activePaintingResource = solidPaintingResource; | |
| 110 } | |
| 111 | 94 |
| 112 bool isVerticalText = false; | 95 bool isVerticalText = false; |
| 113 if (parentRenderObject) { | 96 if (RenderObject* parentRenderObject = firstParentRendererForNonTextNode(ren
derObject)) { |
| 114 parentRenderObjectStyle = parentRenderObject->style(); | 97 RenderStyle* parentRenderObjectStyle = parentRenderObject->style(); |
| 115 ASSERT(parentRenderObjectStyle); | 98 ASSERT(parentRenderObjectStyle); |
| 116 isVerticalText = parentRenderObjectStyle->svgStyle().isVerticalWritingMo
de(); | 99 isVerticalText = parentRenderObjectStyle->svgStyle().isVerticalWritingMo
de(); |
| 117 } | 100 } |
| 118 | 101 |
| 119 float scale = scaleEmToUnits(fontData->platformData().size(), fontFaceElemen
t->unitsPerEm()); | 102 float scale = scaleEmToUnits(fontData->platformData().size(), fontFaceElemen
t->unitsPerEm()); |
| 120 ASSERT(activePaintingResource); | |
| 121 | 103 |
| 122 FloatPoint glyphOrigin; | 104 FloatPoint glyphOrigin; |
| 123 glyphOrigin.setX(svgFontData->horizontalOriginX() * scale); | 105 glyphOrigin.setX(svgFontData->horizontalOriginX() * scale); |
| 124 glyphOrigin.setY(svgFontData->horizontalOriginY() * scale); | 106 glyphOrigin.setY(svgFontData->horizontalOriginY() * scale); |
| 125 | 107 |
| 126 unsigned short resourceMode = context->textDrawingMode() == TextModeStroke ?
ApplyToStrokeMode : ApplyToFillMode; | 108 unsigned short resourceMode = context->textDrawingMode() == TextModeStroke ?
ApplyToStrokeMode : ApplyToFillMode; |
| 127 // From a resource perspective this ought to be treated as "text mode". | |
| 128 resourceMode |= ApplyToTextMode; | |
| 129 | 109 |
| 130 FloatPoint currentPoint = point; | 110 FloatPoint currentPoint = point; |
| 131 for (int i = 0; i < numGlyphs; ++i) { | 111 for (int i = 0; i < numGlyphs; ++i) { |
| 132 Glyph glyph = glyphBuffer.glyphAt(from + i); | 112 Glyph glyph = glyphBuffer.glyphAt(from + i); |
| 133 if (!glyph) | 113 if (!glyph) |
| 134 continue; | 114 continue; |
| 135 | 115 |
| 136 float advance = glyphBuffer.advanceAt(from + i).width(); | 116 float advance = glyphBuffer.advanceAt(from + i).width(); |
| 137 SVGGlyph svgGlyph = fontElement->svgGlyphForGlyph(glyph); | 117 SVGGlyph svgGlyph = fontElement->svgGlyphForGlyph(glyph); |
| 138 ASSERT(!svgGlyph.isPartOfLigature); | 118 ASSERT(!svgGlyph.isPartOfLigature); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 154 glyphOrigin.setY(svgGlyph.verticalOriginY * scale); | 134 glyphOrigin.setY(svgGlyph.verticalOriginY * scale); |
| 155 } | 135 } |
| 156 | 136 |
| 157 AffineTransform glyphPathTransform; | 137 AffineTransform glyphPathTransform; |
| 158 glyphPathTransform.translate(currentPoint.x() + glyphOrigin.x(), current
Point.y() + glyphOrigin.y()); | 138 glyphPathTransform.translate(currentPoint.x() + glyphOrigin.x(), current
Point.y() + glyphOrigin.y()); |
| 159 glyphPathTransform.scale(scale, -scale); | 139 glyphPathTransform.scale(scale, -scale); |
| 160 | 140 |
| 161 Path glyphPath = svgGlyph.pathData; | 141 Path glyphPath = svgGlyph.pathData; |
| 162 glyphPath.transform(glyphPathTransform); | 142 glyphPath.transform(glyphPathTransform); |
| 163 | 143 |
| 164 if (activePaintingResource->applyResource(parentRenderObject, parentRend
erObjectStyle, context, resourceMode)) { | 144 SVGRenderSupport::fillOrStrokePath(context, resourceMode, glyphPath); |
| 165 float strokeThickness = context->strokeThickness(); | |
| 166 if (renderObject && renderObject->isSVGInlineText()) | |
| 167 context->setStrokeThickness(strokeThickness * toRenderSVGInlineT
ext(renderObject)->scalingFactor()); | |
| 168 SVGRenderSupport::fillOrStrokePath(context, resourceMode, glyphPath)
; | |
| 169 activePaintingResource->postApplyResource(parentRenderObject, contex
t); | |
| 170 context->setStrokeThickness(strokeThickness); | |
| 171 } | |
| 172 | 145 |
| 173 if (isVerticalText) | 146 if (isVerticalText) |
| 174 currentPoint.move(0, advance); | 147 currentPoint.move(0, advance); |
| 175 else | 148 else |
| 176 currentPoint.move(advance, 0); | 149 currentPoint.move(advance, 0); |
| 177 } | 150 } |
| 178 } | 151 } |
| 179 | 152 |
| 180 GlyphData SVGTextRunRenderingContext::glyphDataForCharacter(const Font& font, co
nst TextRun& run, WidthIterator& iterator, UChar32 character, bool mirror, int c
urrentCharacter, unsigned& advanceLength) | 153 GlyphData SVGTextRunRenderingContext::glyphDataForCharacter(const Font& font, co
nst TextRun& run, WidthIterator& iterator, UChar32 character, bool mirror, int c
urrentCharacter, unsigned& advanceLength) |
| 181 { | 154 { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // Restore original state of the SVG Font glyph table and the current font f
allback list, | 220 // Restore original state of the SVG Font glyph table and the current font f
allback list, |
| 248 // to assure the next lookup of the same glyph won't immediately return the
fallback glyph. | 221 // to assure the next lookup of the same glyph won't immediately return the
fallback glyph. |
| 249 page->setGlyphDataForCharacter(character, glyphData.glyph, originalFontData)
; | 222 page->setGlyphDataForCharacter(character, glyphData.glyph, originalFontData)
; |
| 250 ASSERT(fallbackGlyphData.fontData); | 223 ASSERT(fallbackGlyphData.fontData); |
| 251 return fallbackGlyphData; | 224 return fallbackGlyphData; |
| 252 } | 225 } |
| 253 | 226 |
| 254 } | 227 } |
| 255 | 228 |
| 256 #endif | 229 #endif |
| OLD | NEW |