1 /*
2 * Copyright (C) 2007 Ryan Leavengood <leavengood@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.
charUnicodeToUTF8HACK(unsigned short glyph,char * out)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
canReturnFallbackFontsForComplexText()63 bool Font::canReturnFallbackFontsForComplexText()
64 {
65 return false;
66 }
67
canExpandAroundIdeographsInComplexText()68 bool Font::canExpandAroundIdeographsInComplexText()
69 {
70 return false;
71 }
72
drawGlyphs(GraphicsContext * graphicsContext,const SimpleFontData * font,const GlyphBuffer & glyphBuffer,int from,int numGlyphs,const FloatPoint & point) const73 void Font::drawGlyphs(GraphicsContext* graphicsContext, const SimpleFontData* font,
74 const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
75 {
76 Color color = graphicsContext->fillColor();
77 BView* view = graphicsContext->platformContext();
78 BFont* m_font = font->platformData().font();
79
80 graphicsContext->setCompositeOperation(CompositeSourceOver);
81 view->SetHighColor(color);
82 view->SetFont(m_font);
83
84 GlyphBufferGlyph* glyphs = const_cast<GlyphBufferGlyph*>(glyphBuffer.glyphs(from));
85 float offset = point.x();
86 for (int i = 0; i < numGlyphs; i++) {
87 char out[4];
88 charUnicodeToUTF8HACK(glyphs[i], out);
89
90 view->DrawString(out, sizeof(out), BPoint(offset, point.y()));
91 offset += glyphBuffer.advanceAt(from + i);
92 }
93 }
94
drawComplexText(GraphicsContext * ctx,const TextRun & run,const FloatPoint & point,int from,int to) const95 void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point,
96 int from, int to) const
97 {
98 notImplemented();
99 }
100
drawEmphasisMarksForComplexText(GraphicsContext *,const TextRun &,const AtomicString &,const FloatPoint &,int,int) const101 void Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, int /* from */, int /* to */) const
102 {
103 notImplemented();
104 }
105
floatWidthForComplexText(const TextRun & run,HashSet<const SimpleFontData * > * fallbackFonts,GlyphOverflow * glyphOverflow) const106 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
107 {
108 notImplemented();
109 return 0;
110 }
111
selectionRectForComplexText(const TextRun &,const FloatPoint &,int,int,int) const112 FloatRect Font::selectionRectForComplexText(const TextRun&, const FloatPoint&, int, int, int) const
113 {
114 notImplemented();
115 return FloatRect();
116 }
117
offsetForPositionForComplexText(const TextRun &,float,bool) const118 int Font::offsetForPositionForComplexText(const TextRun&, float, bool) const
119 {
120 notImplemented();
121 return 0;
122 }
123
124 } // namespace WebCore
125
126