1/* 2 * 3 * (C) Copyright IBM Corp. 1998-2005 - 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 13U_NAMESPACE_BEGIN 14 15void 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: just use x, y coordinate, like format 1... 45 const Format1AnchorTable *f1 = (const Format1AnchorTable *) this; 46 47 f1->getAnchor(fontInstance, anchor); 48 break; 49 } 50} 51 52void Format1AnchorTable::getAnchor(const LEFontInstance *fontInstance, LEPoint &anchor) const 53{ 54 le_int16 x = SWAPW(xCoordinate); 55 le_int16 y = SWAPW(yCoordinate); 56 LEPoint pixels; 57 58 fontInstance->transformFunits(x, y, pixels); 59 60 fontInstance->pixelsToUnits(pixels, anchor); 61} 62 63void Format2AnchorTable::getAnchor(LEGlyphID glyphID, const LEFontInstance *fontInstance, LEPoint &anchor) const 64{ 65 LEPoint point; 66 67 if (! fontInstance->getGlyphPoint(glyphID, SWAPW(anchorPoint), point)) { 68 le_int16 x = SWAPW(xCoordinate); 69 le_int16 y = SWAPW(yCoordinate); 70 71 fontInstance->transformFunits(x, y, point); 72 } 73 74 75 fontInstance->pixelsToUnits(point, anchor); 76} 77 78void Format3AnchorTable::getAnchor(const LEFontInstance *fontInstance, LEPoint &anchor) const 79{ 80 le_int16 x = SWAPW(xCoordinate); 81 le_int16 y = SWAPW(yCoordinate); 82 LEPoint pixels; 83 Offset dtxOffset = SWAPW(xDeviceTableOffset); 84 Offset dtyOffset = SWAPW(yDeviceTableOffset); 85 86 fontInstance->transformFunits(x, y, pixels); 87 88 if (dtxOffset != 0) { 89 const DeviceTable *dtx = (const DeviceTable *) ((char *) this + dtxOffset); 90 le_int16 adjx = dtx->getAdjustment((le_int16) fontInstance->getXPixelsPerEm()); 91 92 pixels.fX += adjx; 93 } 94 95 if (dtyOffset != 0) { 96 const DeviceTable *dty = (const DeviceTable *) ((char *) this + dtyOffset); 97 le_int16 adjy = dty->getAdjustment((le_int16) fontInstance->getYPixelsPerEm()); 98 99 pixels.fY += adjy; 100 } 101 102 fontInstance->pixelsToUnits(pixels, anchor); 103} 104 105U_NAMESPACE_END 106 107