1231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block/*
2231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * Copyright (C) 2007 Ryan Leavengood <leavengood@gmail.com>
3231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *
4231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * All rights reserved.
5231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *
6231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * Redistribution and use in source and binary forms, with or without
7231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * modification, are permitted provided that the following conditions
8231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * are met:
9231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * 1. Redistributions of source code must retain the above copyright
10231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *    notice, this list of conditions and the following disclaimer.
11231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * 2. Redistributions in binary form must reproduce the above copyright
12231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *    notice, this list of conditions and the following disclaimer in the
13231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *    documentation and/or other materials provided with the distribution.
14231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *
15231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block */
27231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
28231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "config.h"
29231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "Font.h"
30231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
31231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "FontData.h"
32231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "FontDescription.h"
33231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "FontSelector.h"
34231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "GraphicsContext.h"
35231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "NotImplemented.h"
36231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include <Font.h>
37231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include <String.h>
38231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include <View.h>
39231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
40231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
41231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block// FIXME: Temp routine to convert unicode character to UTF8.
42231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockint charUnicodeToUTF8HACK(unsigned short glyph, char* out)
43231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{
44231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    int i = 0;
45231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
46231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    if (glyph < 0x0080)
47231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        out[i++] = static_cast<char>(glyph);
48231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    else if (glyph < 0x0800) {  // 2 bytes
49231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        out[i++] = 0xc0 | (glyph >> 6);
50231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        out[i++] = 0x80 | (glyph & 0x3F);
51231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    } else if (glyph > 0x0800) {  // 3 bytes
52231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        out[i++] = 0xe0 | (glyph >> 12);
53231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        out[i++] = 0x80 | ((glyph >> 6) & 0x3F);
54231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        out[i++] = 0x80 | (glyph & 0x3F);
55231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    }
56231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
57231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    out[i] = '\0';
58231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    return i;
59231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block}
60231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
61231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blocknamespace WebCore {
62231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
63231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockbool Font::canReturnFallbackFontsForComplexText()
64231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{
65231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    return false;
66231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block}
67231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
682fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockbool Font::canExpandAroundIdeographsInComplexText()
692fc2651226baac27029e38c9d6ef883fa32084dbSteve Block{
702fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    return false;
712fc2651226baac27029e38c9d6ef883fa32084dbSteve Block}
722fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
73231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockvoid Font::drawGlyphs(GraphicsContext* graphicsContext, const SimpleFontData* font,
74231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block                      const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
75231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{
76231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    Color color = graphicsContext->fillColor();
77231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    BView* view = graphicsContext->platformContext();
78231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    BFont* m_font = font->platformData().font();
79231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
80231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    graphicsContext->setCompositeOperation(CompositeSourceOver);
81231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    view->SetHighColor(color);
82231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    view->SetFont(m_font);
83231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
84231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    GlyphBufferGlyph* glyphs = const_cast<GlyphBufferGlyph*>(glyphBuffer.glyphs(from));
85231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    float offset = point.x();
86231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    for (int i = 0; i < numGlyphs; i++) {
87231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        char out[4];
88231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        charUnicodeToUTF8HACK(glyphs[i], out);
89231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
90231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        view->DrawString(out, sizeof(out), BPoint(offset, point.y()));
91231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        offset += glyphBuffer.advanceAt(from + i);
92231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    }
93231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block}
94231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
95231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockvoid Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point,
96231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block                           int from, int to) const
97231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{
98231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    notImplemented();
99231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block}
100231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
101f05b935882198ccf7d81675736e3aeb089c5113aBen Murdochvoid Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, int /* from */, int /* to */) const
102f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch{
103f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    notImplemented();
104f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch}
105231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
106dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockfloat Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
107231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{
108231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    notImplemented();
109231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    return 0;
110231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block}
111231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
11206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian MonsenFloatRect Font::selectionRectForComplexText(const TextRun&, const FloatPoint&, int, int, int) const
113231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{
114231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    notImplemented();
115231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    return FloatRect();
116231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block}
117231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
11806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsenint Font::offsetForPositionForComplexText(const TextRun&, float, bool) const
119231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{
120231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    notImplemented();
121231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    return 0;
122231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block}
123231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
124231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block} // namespace WebCore
125231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
126