Home | History | Annotate | Download | only in haiku
      1 /*
      2  * Copyright (C) 2007 Ryan Leavengood <leavengood (at) gmail.com>
      3  *
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      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  *
     15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #include "config.h"
     29 #include "Font.h"
     30 
     31 #include "FontData.h"
     32 #include "FontDescription.h"
     33 #include "FontSelector.h"
     34 #include "GraphicsContext.h"
     35 #include "NotImplemented.h"
     36 #include <Font.h>
     37 #include <String.h>
     38 #include <View.h>
     39 
     40 
     41 // FIXME: Temp routine to convert unicode character to UTF8.
     42 int charUnicodeToUTF8HACK(unsigned short glyph, char* out)
     43 {
     44     int i = 0;
     45 
     46     if (glyph < 0x0080)
     47         out[i++] = static_cast<char>(glyph);
     48     else if (glyph < 0x0800) {  // 2 bytes
     49         out[i++] = 0xc0 | (glyph >> 6);
     50         out[i++] = 0x80 | (glyph & 0x3F);
     51     } else if (glyph > 0x0800) {  // 3 bytes
     52         out[i++] = 0xe0 | (glyph >> 12);
     53         out[i++] = 0x80 | ((glyph >> 6) & 0x3F);
     54         out[i++] = 0x80 | (glyph & 0x3F);
     55     }
     56 
     57     out[i] = '\0';
     58     return i;
     59 }
     60 
     61 namespace WebCore {
     62 
     63 bool Font::canReturnFallbackFontsForComplexText()
     64 {
     65     return false;
     66 }
     67 
     68 void Font::drawGlyphs(GraphicsContext* graphicsContext, const SimpleFontData* font,
     69                       const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
     70 {
     71     Color color = graphicsContext->fillColor();
     72     BView* view = graphicsContext->platformContext();
     73     BFont* m_font = font->platformData().font();
     74 
     75     graphicsContext->setCompositeOperation(CompositeSourceOver);
     76     view->SetHighColor(color);
     77     view->SetFont(m_font);
     78 
     79     GlyphBufferGlyph* glyphs = const_cast<GlyphBufferGlyph*>(glyphBuffer.glyphs(from));
     80     float offset = point.x();
     81     for (int i = 0; i < numGlyphs; i++) {
     82         char out[4];
     83         charUnicodeToUTF8HACK(glyphs[i], out);
     84 
     85         view->DrawString(out, sizeof(out), BPoint(offset, point.y()));
     86         offset += glyphBuffer.advanceAt(from + i);
     87     }
     88 }
     89 
     90 void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point,
     91                            int from, int to) const
     92 {
     93     notImplemented();
     94 }
     95 
     96 
     97 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts) const
     98 {
     99     notImplemented();
    100     return 0;
    101 }
    102 
    103 FloatRect Font::selectionRectForComplexText(const TextRun&, const IntPoint&, int, int, int) const
    104 {
    105     notImplemented();
    106     return FloatRect();
    107 }
    108 
    109 int Font::offsetForPositionForComplexText(const TextRun&, int, bool) const
    110 {
    111     notImplemented();
    112     return 0;
    113 }
    114 
    115 } // namespace WebCore
    116 
    117