OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2015 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 |
| 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. |
| 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ |
| 25 |
| 26 #include "config.h" |
| 27 #include "platform/fonts/shaping/CachingWordShaper.h" |
| 28 |
| 29 #include "platform/fonts/SimpleFontData.h" |
| 30 #include "platform/fonts/shaping/CachingWordShapeIterator.h" |
| 31 #include "platform/fonts/shaping/HarfBuzzShaper.h" |
| 32 #include "platform/fonts/shaping/ShapeCache.h" |
| 33 #include "wtf/text/CharacterNames.h" |
| 34 |
| 35 namespace blink { |
| 36 |
| 37 CachingWordShaper::CachingWordShaper() |
| 38 { |
| 39 m_shapeCache = new ShapeCache(); |
| 40 } |
| 41 |
| 42 CachingWordShaper::~CachingWordShaper() |
| 43 { |
| 44 delete m_shapeCache; |
| 45 } |
| 46 |
| 47 void CachingWordShaper::clear() |
| 48 { |
| 49 if (m_shapeCache) |
| 50 m_shapeCache->clear(); |
| 51 } |
| 52 |
| 53 float CachingWordShaper::width(const Font* font, const TextRun& run, |
| 54 HashSet<const SimpleFontData*>* fallbackFonts, |
| 55 FloatRect* glyphBounds) |
| 56 { |
| 57 float width = 0; |
| 58 RefPtr<ShapeResult> wordResult; |
| 59 CachingWordShapeIterator iterator(m_shapeCache, run, font, fallbackFonts); |
| 60 while (iterator.next(&wordResult)) { |
| 61 if (wordResult) { |
| 62 width += wordResult->width(); |
| 63 if (glyphBounds) |
| 64 glyphBounds->unite(wordResult->bounds()); |
| 65 } |
| 66 } |
| 67 |
| 68 return width; |
| 69 } |
| 70 |
| 71 static inline float shapeResultsForRun(ShapeCache* shapeCache, const Font* font, |
| 72 const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, |
| 73 Vector<RefPtr<ShapeResult>>* results) |
| 74 { |
| 75 CachingWordShapeIterator iterator(shapeCache, run, font, fallbackFonts); |
| 76 RefPtr<ShapeResult> wordResult; |
| 77 float totalWidth = 0; |
| 78 while (iterator.next(&wordResult)) { |
| 79 if (wordResult) { |
| 80 results->append(wordResult); |
| 81 totalWidth += wordResult->width(); |
| 82 } |
| 83 } |
| 84 return totalWidth; |
| 85 } |
| 86 |
| 87 float CachingWordShaper::fillGlyphBuffer(const Font* font, const TextRun& run, |
| 88 HashSet<const SimpleFontData*>* fallbackFonts, |
| 89 GlyphBuffer* glyphBuffer, unsigned from, unsigned to) |
| 90 { |
| 91 Vector<RefPtr<ShapeResult>> results; |
| 92 shapeResultsForRun(m_shapeCache, font, run, fallbackFonts, &results); |
| 93 |
| 94 return ShapeResult::fillGlyphBuffer(results, glyphBuffer, run, from, to); |
| 95 } |
| 96 |
| 97 float CachingWordShaper::fillGlyphBufferForTextEmphasis(const Font* font, |
| 98 const TextRun& run, const GlyphData* emphasisData, GlyphBuffer* glyphBuffer, |
| 99 unsigned from, unsigned to) |
| 100 { |
| 101 Vector<RefPtr<ShapeResult>> results; |
| 102 shapeResultsForRun(m_shapeCache, font, run, nullptr, &results); |
| 103 |
| 104 return ShapeResult::fillGlyphBufferForTextEmphasis(results, glyphBuffer, |
| 105 run, emphasisData, from, to); |
| 106 } |
| 107 |
| 108 FloatRect CachingWordShaper::selectionRect(const Font* font, const TextRun& run, |
| 109 const FloatPoint& point, int height, unsigned from, unsigned to) |
| 110 { |
| 111 Vector<RefPtr<ShapeResult>> results; |
| 112 float totalWidth = shapeResultsForRun(m_shapeCache, font, run, nullptr, |
| 113 &results); |
| 114 |
| 115 return ShapeResult::selectionRect(results, run.direction(), totalWidth, |
| 116 point, height, from, to); |
| 117 } |
| 118 |
| 119 }; // namespace blink |
OLD | NEW |