15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
2591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved.
3591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * met:
7591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch *
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions of source code must retain the above copyright
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions in binary form must reproduce the above
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * in the documentation and/or other materials provided with the
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * distribution.
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * contributors may be used to endorse or promote products derived from
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this software without specific prior written permission.
17591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch *
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
32a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/fonts/FontPlatformData.h"
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
34591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "SkEndian.h"
35591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "SkTypeface.h"
36a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/fonts/FontCache.h"
375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
38c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
40d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#if !OS(MACOSX)
411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)unsigned FontPlatformData::hash() const
421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    unsigned h = SkTypeface::UniqueID(m_typeface.get());
447242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    h ^= 0x01010101 * ((static_cast<int>(m_isHashTableDeletedValue) << 3) | (static_cast<int>(m_orientation) << 2) | (static_cast<int>(m_syntheticBold) << 1) | static_cast<int>(m_syntheticItalic));
451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // This memcpy is to avoid a reinterpret_cast that breaks strict-aliasing
471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // rules. Memcpy is generally optimized enough so that performance doesn't
481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // matter here.
491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    uint32_t textSizeBytes;
501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    memcpy(&textSizeBytes, &m_textSize, sizeof(uint32_t));
511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    h ^= textSizeBytes;
521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    return h;
541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
56197021e6b966cfb06891637935ef33fff06433d1Ben Murdochbool FontPlatformData::fontContainsCharacter(UChar32 character)
57197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch{
58197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    SkPaint paint;
59197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    setupPaint(&paint);
60197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
61197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
62197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    uint16_t glyph;
63197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    paint.textToGlyphs(&character, sizeof(character), &glyph);
64197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    return glyph;
65197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch}
66197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#endif
681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
69591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#if ENABLE(OPENTYPE_VERTICAL)
70591b958dee2cf159d33a0b931e6231072eaf38d5Ben MurdochPassRefPtr<OpenTypeVerticalData> FontPlatformData::verticalData() const
715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
72a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    return FontCache::fontCache()->getVerticalData(typeface()->uniqueID(), *this);
73591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch}
74591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
75591b958dee2cf159d33a0b931e6231072eaf38d5Ben MurdochPassRefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const
76591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch{
77591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    RefPtr<SharedBuffer> buffer;
78591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
79591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    SkFontTableTag tag = SkEndianSwap32(table);
80591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    const size_t tableSize = m_typeface->getTableSize(tag);
81591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    if (tableSize) {
82591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        Vector<char> tableBuffer(tableSize);
83591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        m_typeface->getTableData(tag, 0, tableSize, &tableBuffer[0]);
84591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        buffer = SharedBuffer::adoptVector(tableBuffer);
855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
86591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    return buffer.release();
875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
88591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#endif
895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
90c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
91