blob: caaf349afd6f0a31df0ec92ff5d7f3347adedcc4 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * This code is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation. Sun designates this
7 * particular file as subject to the "Classpath" exception as provided
8 * by Sun in the LICENSE file that accompanied this code.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 */
25
26/*
27 *
28 * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
29 *
30 */
31
32#include "LETypes.h"
33#include "LEFontInstance.h"
34#include "DeviceTables.h"
35#include "AnchorTables.h"
36#include "LESwaps.h"
37
38void AnchorTable::getAnchor(LEGlyphID glyphID, const LEFontInstance *fontInstance,
39 LEPoint &anchor) const
40{
41 switch(SWAPW(anchorFormat)) {
42 case 1:
43 {
44 const Format1AnchorTable *f1 = (const Format1AnchorTable *) this;
45
46 f1->getAnchor(fontInstance, anchor);
47 break;
48 }
49
50 case 2:
51 {
52 const Format2AnchorTable *f2 = (const Format2AnchorTable *) this;
53
54 f2->getAnchor(glyphID, fontInstance, anchor);
55 break;
56 }
57
58 case 3:
59 {
60 const Format3AnchorTable *f3 = (const Format3AnchorTable *) this;
61
62 f3->getAnchor(fontInstance, anchor);
63 break;
64 }
65
66 default:
67 // unknown format: just use x, y coordinate, like format 1...
68 const Format1AnchorTable *f1 = (const Format1AnchorTable *) this;
69
70 f1->getAnchor(fontInstance, anchor);
71 break;
72 }
73}
74
75void Format1AnchorTable::getAnchor(const LEFontInstance *fontInstance, LEPoint &anchor) const
76{
77 le_int16 x = SWAPW(xCoordinate);
78 le_int16 y = SWAPW(yCoordinate);
79 LEPoint pixels;
80
81 fontInstance->transformFunits(x, y, pixels);
82
83 fontInstance->pixelsToUnits(pixels, anchor);
84}
85
86void Format2AnchorTable::getAnchor(LEGlyphID glyphID, const LEFontInstance *fontInstance, LEPoint &anchor) const
87{
88 LEPoint point;
89
90 if (! fontInstance->getGlyphPoint(glyphID, SWAPW(anchorPoint), point)) {
91 le_int16 x = SWAPW(xCoordinate);
92 le_int16 y = SWAPW(yCoordinate);
93
94 fontInstance->transformFunits(x, y, point);
95 }
96
97
98 fontInstance->pixelsToUnits(point, anchor);
99}
100
101void Format3AnchorTable::getAnchor(const LEFontInstance *fontInstance, LEPoint &anchor) const
102{
103 le_int16 x = SWAPW(xCoordinate);
104 le_int16 y = SWAPW(yCoordinate);
105 LEPoint pixels;
106 Offset dtxOffset = SWAPW(xDeviceTableOffset);
107 Offset dtyOffset = SWAPW(yDeviceTableOffset);
108
109 fontInstance->transformFunits(x, y, pixels);
110
111 if (dtxOffset != 0) {
112 const DeviceTable *dtx = (const DeviceTable *) ((char *) this + dtxOffset);
113 le_int16 adjx = dtx->getAdjustment((le_int16) fontInstance->getXPixelsPerEm());
114
115 pixels.fX += adjx;
116 }
117
118 if (dtyOffset != 0) {
119 const DeviceTable *dty = (const DeviceTable *) ((char *) this + dtyOffset);
120 le_int16 adjy = dty->getAdjustment((le_int16) fontInstance->getYPixelsPerEm());
121
122 pixels.fY += adjy;
123 }
124
125 fontInstance->pixelsToUnits(pixels, anchor);
126}