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/unicode/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 float CachingWordShaper::fillGlyphBuffer(const Font* font, const TextRun& run, |
| 72 HashSet<const SimpleFontData*>* fallbackFonts, |
| 73 GlyphBuffer* glyphBuffer, unsigned from, unsigned to) |
| 74 { |
| 75 CachingWordShapeIterator iterator(m_shapeCache, run, font, fallbackFonts); |
| 76 RefPtr<ShapeResult> wordResult; |
| 77 Vector<RefPtr<ShapeResult>> results; |
| 78 unsigned totalChars = 0; |
| 79 float width = 0; |
| 80 while (iterator.next(&wordResult)) { |
| 81 if (wordResult) { |
| 82 results.append(wordResult); |
| 83 totalChars += wordResult->numCharacters(); |
| 84 width += wordResult->width(); |
| 85 } |
| 86 } |
| 87 |
| 88 float advance = 0; |
| 89 if (run.rtl()) { |
| 90 unsigned wordOffset = totalChars; |
| 91 for (unsigned i = 0; i < results.size(); i++) { |
| 92 unsigned resolvedIndex = results.size() - 1 - i; |
| 93 RefPtr<ShapeResult>& wordResult = results[resolvedIndex]; |
| 94 advance += wordResult->fillGlyphBuffer(glyphBuffer, advance, |
| 95 from, to, wordOffset - wordResult->numCharacters()); |
| 96 wordOffset -= wordResult->numCharacters(); |
| 97 } |
| 98 } else { |
| 99 unsigned wordOffset = 0; |
| 100 for (unsigned i = 0; i < results.size(); i++) { |
| 101 RefPtr<ShapeResult>& wordResult = results[i]; |
| 102 advance += wordResult->fillGlyphBuffer(glyphBuffer, advance, |
| 103 from, to, wordOffset); |
| 104 wordOffset += wordResult->numCharacters(); |
| 105 } |
| 106 } |
| 107 |
| 108 return width; |
| 109 } |
| 110 |
| 111 }; // namespace blink |
OLD | NEW |