Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 #include "wtf/unicode/CharacterNames.h" | 39 #include "wtf/unicode/CharacterNames.h" |
| 40 #include "wtf/unicode/Unicode.h" | 40 #include "wtf/unicode/Unicode.h" |
| 41 | 41 |
| 42 using namespace WTF; | 42 using namespace WTF; |
| 43 using namespace Unicode; | 43 using namespace Unicode; |
| 44 | 44 |
| 45 namespace WebCore { | 45 namespace WebCore { |
| 46 | 46 |
| 47 SVGFontData::SVGFontData(SVGFontFaceElement* fontFaceElement) | 47 SVGFontData::SVGFontData(SVGFontFaceElement* fontFaceElement) |
| 48 : CustomFontData() | 48 : CustomFontData() |
| 49 , m_svgFontFaceElement(fontFaceElement) | 49 , m_svgFontFaceElement(fontFaceElement->createWeakRef()) |
| 50 , m_horizontalOriginX(fontFaceElement->horizontalOriginX()) | 50 , m_horizontalOriginX(fontFaceElement->horizontalOriginX()) |
| 51 , m_horizontalOriginY(fontFaceElement->horizontalOriginY()) | 51 , m_horizontalOriginY(fontFaceElement->horizontalOriginY()) |
| 52 , m_horizontalAdvanceX(fontFaceElement->horizontalAdvanceX()) | 52 , m_horizontalAdvanceX(fontFaceElement->horizontalAdvanceX()) |
| 53 , m_verticalOriginX(fontFaceElement->verticalOriginX()) | 53 , m_verticalOriginX(fontFaceElement->verticalOriginX()) |
| 54 , m_verticalOriginY(fontFaceElement->verticalOriginY()) | 54 , m_verticalOriginY(fontFaceElement->verticalOriginY()) |
| 55 , m_verticalAdvanceY(fontFaceElement->verticalAdvanceY()) | 55 , m_verticalAdvanceY(fontFaceElement->verticalAdvanceY()) |
| 56 { | 56 { |
| 57 ASSERT_ARG(fontFaceElement, fontFaceElement); | 57 ASSERT_ARG(fontFaceElement, fontFaceElement); |
| 58 } | 58 } |
| 59 | 59 |
| 60 SVGFontData::~SVGFontData() | |
| 61 { | |
| 62 } | |
| 63 | |
| 60 void SVGFontData::initializeFontData(SimpleFontData* fontData, float fontSize) | 64 void SVGFontData::initializeFontData(SimpleFontData* fontData, float fontSize) |
| 61 { | 65 { |
| 62 ASSERT(fontData); | 66 ASSERT(fontData); |
| 63 | 67 |
| 64 SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement(); | 68 SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement(); |
| 65 ASSERT(svgFontFaceElement && svgFontFaceElement->inDocument()); | |
| 66 | 69 |
| 67 SVGFontElement* svgFontElement = svgFontFaceElement->associatedFontElement() ; | 70 SVGFontElement* svgFontElement = svgFontFaceElement->associatedFontElement() ; |
| 68 ASSERT(svgFontElement); | 71 ASSERT(svgFontElement); |
| 69 GlyphData missingGlyphData; | 72 GlyphData missingGlyphData; |
| 70 missingGlyphData.fontData = fontData; | 73 missingGlyphData.fontData = fontData; |
| 71 missingGlyphData.glyph = svgFontElement->missingGlyph(); | 74 missingGlyphData.glyph = svgFontElement->missingGlyph(); |
| 72 fontData->setMissingGlyphData(missingGlyphData); | 75 fontData->setMissingGlyphData(missingGlyphData); |
| 73 | 76 |
| 74 fontData->setZeroWidthSpaceGlyph(0); | 77 fontData->setZeroWidthSpaceGlyph(0); |
| 75 fontData->determinePitch(); | 78 fontData->determinePitch(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 Glyph numeralZeroGlyph = glyphPageZero->glyphForCharacter('0'); | 117 Glyph numeralZeroGlyph = glyphPageZero->glyphForCharacter('0'); |
| 115 fontData->setAvgCharWidth(numeralZeroGlyph ? fontData->widthForGlyph(numeral ZeroGlyph) : fontData->spaceWidth()); | 118 fontData->setAvgCharWidth(numeralZeroGlyph ? fontData->widthForGlyph(numeral ZeroGlyph) : fontData->spaceWidth()); |
| 116 | 119 |
| 117 // Estimate maximum character width. | 120 // Estimate maximum character width. |
| 118 Glyph letterWGlyph = glyphPageZero->glyphForCharacter('W'); | 121 Glyph letterWGlyph = glyphPageZero->glyphForCharacter('W'); |
| 119 fontData->setMaxCharWidth(letterWGlyph ? fontData->widthForGlyph(letterWGlyp h) : ascent); | 122 fontData->setMaxCharWidth(letterWGlyph ? fontData->widthForGlyph(letterWGlyp h) : ascent); |
| 120 } | 123 } |
| 121 | 124 |
| 122 float SVGFontData::widthForSVGGlyph(Glyph glyph, float fontSize) const | 125 float SVGFontData::widthForSVGGlyph(Glyph glyph, float fontSize) const |
| 123 { | 126 { |
| 127 // FIXME: (http://crbug.com/359380) Width calculation may be triggered after removeNode from the current editing impl. | |
| 128 // The retrieved width is not being used, so here we return a dummy value. | |
| 129 if (shouldSkipDrawing()) | |
| 130 return 0.0; | |
| 131 | |
| 124 SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement(); | 132 SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement(); |
| 125 ASSERT(svgFontFaceElement); | 133 |
| 126 // RenderView::clearSelection is invoked while removing some element, e.g. | 134 // RenderView::clearSelection is invoked while removing some element, e.g. |
| 127 // Document::nodeWillBeRemoved => FrameSelection::nodeWillBeRemoved => Rende rView::clearSelection. | 135 // Document::nodeWillBeRemoved => FrameSelection::nodeWillBeRemoved => Rende rView::clearSelection. |
| 128 // Since recalc style has not been executed yet, RenderStyle might have some reference to | 136 // Since recalc style has not been executed yet, RenderStyle might have some reference to |
| 129 // SVGFontFaceElement which was also removed. | 137 // SVGFontFaceElement which was also removed. |
| 130 // In this case, use default horizontalAdvanceX instead of associatedFontEle ment's one. | 138 // In this case, use default horizontalAdvanceX instead of associatedFontEle ment's one. |
| 131 if (!svgFontFaceElement->inDocument()) | 139 if (!svgFontFaceElement->inDocument()) |
| 132 return m_horizontalAdvanceX * scaleEmToUnits(fontSize, svgFontFaceElemen t->unitsPerEm()); | 140 return m_horizontalAdvanceX * scaleEmToUnits(fontSize, svgFontFaceElemen t->unitsPerEm()); |
| 133 | 141 |
| 134 SVGFontElement* associatedFontElement = svgFontFaceElement->associatedFontEl ement(); | 142 SVGFontElement* associatedFontElement = svgFontFaceElement->associatedFontEl ement(); |
| 135 ASSERT(associatedFontElement); | 143 ASSERT(associatedFontElement); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 155 remainingTextInRun = String(run.data16(currentCharacter), run.characters Length() - currentCharacter); | 163 remainingTextInRun = String(run.data16(currentCharacter), run.characters Length() - currentCharacter); |
| 156 remainingTextInRun = Character::normalizeSpaces(remainingTextInRun.chara cters16(), remainingTextInRun.length()); | 164 remainingTextInRun = Character::normalizeSpaces(remainingTextInRun.chara cters16(), remainingTextInRun.length()); |
| 157 } | 165 } |
| 158 | 166 |
| 159 if (mirror) | 167 if (mirror) |
| 160 remainingTextInRun = createStringWithMirroredCharacters(remainingTextInR un); | 168 remainingTextInRun = createStringWithMirroredCharacters(remainingTextInR un); |
| 161 if (!currentCharacter && arabicForms.isEmpty()) | 169 if (!currentCharacter && arabicForms.isEmpty()) |
| 162 arabicForms = charactersWithArabicForm(remainingTextInRun, mirror); | 170 arabicForms = charactersWithArabicForm(remainingTextInRun, mirror); |
| 163 | 171 |
| 164 SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement(); | 172 SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement(); |
| 165 ASSERT(svgFontFaceElement && svgFontFaceElement->inDocument()); | |
| 166 | |
| 167 SVGFontElement* associatedFontElement = svgFontFaceElement->associatedFontEl ement(); | 173 SVGFontElement* associatedFontElement = svgFontFaceElement->associatedFontEl ement(); |
| 168 ASSERT(associatedFontElement); | 174 ASSERT(associatedFontElement); |
| 169 | 175 |
| 170 RenderObject* renderObject = 0; | 176 RenderObject* renderObject = 0; |
| 171 if (TextRun::RenderingContext* renderingContext = run.renderingContext()) | 177 if (TextRun::RenderingContext* renderingContext = run.renderingContext()) |
| 172 renderObject = static_cast<SVGTextRunRenderingContext*>(renderingContext )->renderer(); | 178 renderObject = static_cast<SVGTextRunRenderingContext*>(renderingContext )->renderer(); |
| 173 | 179 |
| 174 String language; | 180 String language; |
| 175 bool isVerticalText = false; | 181 bool isVerticalText = false; |
| 176 Vector<AtomicString> altGlyphNames; | 182 Vector<AtomicString> altGlyphNames; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 | 232 |
| 227 return false; | 233 return false; |
| 228 } | 234 } |
| 229 | 235 |
| 230 bool SVGFontData::fillSVGGlyphPage(GlyphPage* pageToFill, unsigned offset, unsig ned length, UChar* buffer, unsigned bufferLength, const SimpleFontData* fontData ) const | 236 bool SVGFontData::fillSVGGlyphPage(GlyphPage* pageToFill, unsigned offset, unsig ned length, UChar* buffer, unsigned bufferLength, const SimpleFontData* fontData ) const |
| 231 { | 237 { |
| 232 ASSERT(fontData->isCustomFont()); | 238 ASSERT(fontData->isCustomFont()); |
| 233 ASSERT(fontData->isSVGFont()); | 239 ASSERT(fontData->isSVGFont()); |
| 234 | 240 |
| 235 SVGFontFaceElement* fontFaceElement = this->svgFontFaceElement(); | 241 SVGFontFaceElement* fontFaceElement = this->svgFontFaceElement(); |
| 236 ASSERT(fontFaceElement && fontFaceElement->inDocument()); | |
| 237 | |
| 238 SVGFontElement* fontElement = fontFaceElement->associatedFontElement(); | 242 SVGFontElement* fontElement = fontFaceElement->associatedFontElement(); |
| 239 ASSERT(fontElement); | 243 ASSERT(fontElement); |
| 240 | 244 |
| 241 if (bufferLength == length) | 245 if (bufferLength == length) |
| 242 return fillBMPGlyphs(fontElement, pageToFill, offset, length, buffer, fo ntData); | 246 return fillBMPGlyphs(fontElement, pageToFill, offset, length, buffer, fo ntData); |
| 243 | 247 |
| 244 ASSERT(bufferLength == 2 * length); | 248 ASSERT(bufferLength == 2 * length); |
| 245 return fillNonBMPGlyphs(fontElement, pageToFill, offset, length, buffer, fon tData); | 249 return fillNonBMPGlyphs(fontElement, pageToFill, offset, length, buffer, fon tData); |
| 246 } | 250 } |
| 247 | 251 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 while (i < length) { | 318 while (i < length) { |
| 315 UChar32 character; | 319 UChar32 character; |
| 316 U16_NEXT(characters, i, length, character); | 320 U16_NEXT(characters, i, length, character); |
| 317 mirroredCharacters.append(mirroredChar(character)); | 321 mirroredCharacters.append(mirroredChar(character)); |
| 318 } | 322 } |
| 319 } | 323 } |
| 320 | 324 |
| 321 return mirroredCharacters.toString(); | 325 return mirroredCharacters.toString(); |
| 322 } | 326 } |
| 323 | 327 |
| 328 SVGFontFaceElement* SVGFontData::svgFontFaceElement() const | |
| 329 { | |
| 330 // FIXME: SVGFontData should be only used from the document with the SVGFont FaceElement. | |
| 331 RELEASE_ASSERT(m_svgFontFaceElement && m_svgFontFaceElement->inDocument()); | |
| 332 return m_svgFontFaceElement.get(); | |
| 333 } | |
| 334 | |
| 335 bool SVGFontData::shouldSkipDrawing() const | |
| 336 { | |
| 337 return !m_svgFontFaceElement || !m_svgFontFaceElement->inDocument(); | |
|
Kunihiko Sakamoto
2014/04/03 03:17:08
This is workaround for crbug.com/359380, right?
If
kouhei (in TOK)
2014/04/03 09:17:59
Done.
| |
| 338 } | |
| 339 | |
| 324 } // namespace WebCore | 340 } // namespace WebCore |
| 325 | 341 |
| 326 #endif | 342 #endif |
| OLD | NEW |