Home | History | Annotate | Download | only in haiku
      1 /*
      2  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
      3  * Copyright (C) 2009 Maxime Simon <simon.maxime (at) gmail.com> All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *
      9  * 1.  Redistributions of source code must retain the above copyright
     10  *     notice, this list of conditions and the following disclaimer.
     11  * 2.  Redistributions in binary form must reproduce the above copyright
     12  *     notice, this list of conditions and the following disclaimer in the
     13  *     documentation and/or other materials provided with the distribution.
     14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     15  *     its contributors may be used to endorse or promote products derived
     16  *     from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include "config.h"
     31 #include "SimpleFontData.h"
     32 
     33 #include "FloatRect.h"
     34 #include "FontCache.h"
     35 #include "FontDescription.h"
     36 #include "NotImplemented.h"
     37 #include <Rect.h>
     38 #include <unicode/uchar.h>
     39 #include <unicode/unorm.h>
     40 
     41 
     42 extern int charUnicodeToUTF8HACK(unsigned short, char*);
     43 
     44 namespace WebCore {
     45 
     46 void SimpleFontData::platformInit()
     47 {
     48     BFont* font = m_platformData.font();
     49     if (!font)
     50         return;
     51 
     52     font_height height;
     53     font->GetHeight(&height);
     54     m_ascent = static_cast<int>(height.ascent);
     55     m_descent = static_cast<int>(height.descent);
     56     m_lineSpacing = m_ascent + m_descent;
     57     m_xHeight = height.ascent * 0.56f; // Hack taken from the win port.
     58     m_lineGap = height.leading;
     59 }
     60 
     61 void SimpleFontData::platformCharWidthInit()
     62 {
     63     m_avgCharWidth = 0.f;
     64     m_maxCharWidth = 0.f;
     65     initCharWidths();
     66 }
     67 
     68 void SimpleFontData::platformDestroy()
     69 {
     70     delete m_smallCapsFontData;
     71     m_smallCapsFontData = 0;
     72 }
     73 
     74 SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDescription) const
     75 {
     76     if (!m_smallCapsFontData) {
     77         FontDescription desc = FontDescription(fontDescription);
     78         desc.setSpecifiedSize(0.70f * fontDescription.computedSize());
     79         const FontPlatformData* fontPlatformData = new FontPlatformData(desc, desc.family().family());
     80         m_smallCapsFontData = new SimpleFontData(*fontPlatformData);
     81     }
     82     return m_smallCapsFontData;
     83 }
     84 
     85 bool SimpleFontData::containsCharacters(const UChar* characters, int length) const
     86 {
     87     // FIXME: We will need to implement this to load non-ASCII encoding sites
     88     return true;
     89 }
     90 
     91 void SimpleFontData::determinePitch()
     92 {
     93     m_treatAsFixedPitch = m_platformData.font() && m_platformData.font()->IsFixed();
     94 }
     95 
     96 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
     97 {
     98     if (!m_platformData.font())
     99         return 0;
    100 
    101     char charArray[4];
    102     float escapements[1];
    103 
    104     charUnicodeToUTF8HACK(glyph, charArray);
    105     m_platformData.font()->GetEscapements(charArray, 1, escapements);
    106     return escapements[0] * m_platformData.font()->Size();
    107 }
    108 
    109 } // namespace WebCore
    110 
    111