|
1 /* |
|
2 * |
|
3 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved |
|
4 * |
|
5 */ |
|
6 |
|
7 #include "LETypes.h" |
|
8 #include "LEFontInstance.h" |
|
9 #include "DeviceTables.h" |
|
10 #include "AnchorTables.h" |
|
11 #include "LESwaps.h" |
|
12 |
|
13 U_NAMESPACE_BEGIN |
|
14 |
|
15 void AnchorTable::getAnchor(LEGlyphID glyphID, const LEFontInstance *fontInstance, |
|
16 LEPoint &anchor) const |
|
17 { |
|
18 switch(SWAPW(anchorFormat)) { |
|
19 case 1: |
|
20 { |
|
21 const Format1AnchorTable *f1 = (const Format1AnchorTable *) this; |
|
22 |
|
23 f1->getAnchor(fontInstance, anchor); |
|
24 break; |
|
25 } |
|
26 |
|
27 case 2: |
|
28 { |
|
29 const Format2AnchorTable *f2 = (const Format2AnchorTable *) this; |
|
30 |
|
31 f2->getAnchor(glyphID, fontInstance, anchor); |
|
32 break; |
|
33 } |
|
34 |
|
35 case 3: |
|
36 { |
|
37 const Format3AnchorTable *f3 = (const Format3AnchorTable *) this; |
|
38 |
|
39 f3->getAnchor(fontInstance, anchor); |
|
40 break; |
|
41 } |
|
42 |
|
43 default: |
|
44 // Unknown format, set the anchor point to (0, 0) |
|
45 anchor.fX = 0; |
|
46 anchor.fY = 0; |
|
47 break; |
|
48 } |
|
49 } |
|
50 |
|
51 void Format1AnchorTable::getAnchor(const LEFontInstance *fontInstance, LEPoint &anchor) const |
|
52 { |
|
53 le_int16 x = SWAPW(xCoordinate); |
|
54 le_int16 y = SWAPW(yCoordinate); |
|
55 LEPoint pixels; |
|
56 |
|
57 fontInstance->transformFunits(x, y, pixels); |
|
58 |
|
59 fontInstance->pixelsToUnits(pixels, anchor); |
|
60 } |
|
61 |
|
62 void Format2AnchorTable::getAnchor(LEGlyphID glyphID, const LEFontInstance *fontInstance, LEPoint &anchor) const |
|
63 { |
|
64 LEPoint point; |
|
65 |
|
66 if (! fontInstance->getGlyphPoint(glyphID, SWAPW(anchorPoint), point)) { |
|
67 le_int16 x = SWAPW(xCoordinate); |
|
68 le_int16 y = SWAPW(yCoordinate); |
|
69 |
|
70 fontInstance->transformFunits(x, y, point); |
|
71 } |
|
72 |
|
73 |
|
74 fontInstance->pixelsToUnits(point, anchor); |
|
75 } |
|
76 |
|
77 void Format3AnchorTable::getAnchor(const LEFontInstance *fontInstance, LEPoint &anchor) const |
|
78 { |
|
79 le_int16 x = SWAPW(xCoordinate); |
|
80 le_int16 y = SWAPW(yCoordinate); |
|
81 LEPoint pixels; |
|
82 Offset dtxOffset = SWAPW(xDeviceTableOffset); |
|
83 Offset dtyOffset = SWAPW(yDeviceTableOffset); |
|
84 |
|
85 fontInstance->transformFunits(x, y, pixels); |
|
86 |
|
87 if (dtxOffset != 0) { |
|
88 const DeviceTable *dtx = (const DeviceTable *) ((char *) this + dtxOffset); |
|
89 le_int16 adjx = dtx->getAdjustment((le_int16) fontInstance->getXPixelsPerEm()); |
|
90 |
|
91 pixels.fX += adjx; |
|
92 } |
|
93 |
|
94 if (dtyOffset != 0) { |
|
95 const DeviceTable *dty = (const DeviceTable *) ((char *) this + dtyOffset); |
|
96 le_int16 adjy = dty->getAdjustment((le_int16) fontInstance->getYPixelsPerEm()); |
|
97 |
|
98 pixels.fY += adjy; |
|
99 } |
|
100 |
|
101 fontInstance->pixelsToUnits(pixels, anchor); |
|
102 } |
|
103 |
|
104 U_NAMESPACE_END |
|
105 |