Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/font/layout/AnchorTables.cpp
38918 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425/*26*27* (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved28*29*/3031#include "LETypes.h"32#include "LEFontInstance.h"33#include "DeviceTables.h"34#include "AnchorTables.h"35#include "LESwaps.h"3637U_NAMESPACE_BEGIN3839void AnchorTable::getAnchor(const LETableReference &base, LEGlyphID glyphID, const LEFontInstance *fontInstance,40LEPoint &anchor, LEErrorCode &success) const41{42switch(SWAPW(anchorFormat)) {43case 1:44{45LEReferenceTo<Format1AnchorTable> f1(base, success);46if (LE_SUCCESS(success)) {47f1->getAnchor(f1, fontInstance, anchor, success);48}49break;50}5152case 2:53{54LEReferenceTo<Format2AnchorTable> f2(base, success);55if (LE_SUCCESS(success)) {56f2->getAnchor(f2, glyphID, fontInstance, anchor, success);57}58break;59}6061case 3:62{63LEReferenceTo<Format3AnchorTable> f3(base, success);64if (LE_SUCCESS(success)) {65f3->getAnchor(f3, fontInstance, anchor, success);66}67break;68}6970default:71{72// unknown format: just use x, y coordinate, like format 1...73LEReferenceTo<Format1AnchorTable> f1(base, success);74if (LE_SUCCESS(success)) {75f1->getAnchor(f1, fontInstance, anchor, success);76}77break;78}79}80}8182void Format1AnchorTable::getAnchor(const LEReferenceTo<Format1AnchorTable>& base, const LEFontInstance *fontInstance, LEPoint &anchor, LEErrorCode &success) const83{84le_int16 x = SWAPW(xCoordinate);85le_int16 y = SWAPW(yCoordinate);86LEPoint pixels;8788fontInstance->transformFunits(x, y, pixels);89fontInstance->pixelsToUnits(pixels, anchor);90}9192void Format2AnchorTable::getAnchor(const LEReferenceTo<Format2AnchorTable>& base,93LEGlyphID glyphID, const LEFontInstance *fontInstance, LEPoint &anchor94, LEErrorCode &success) const95{96LEPoint point;9798if (! fontInstance->getGlyphPoint(glyphID, SWAPW(anchorPoint), point)) {99le_int16 x = SWAPW(xCoordinate);100le_int16 y = SWAPW(yCoordinate);101102fontInstance->transformFunits(x, y, point);103}104105106fontInstance->pixelsToUnits(point, anchor);107}108109void Format3AnchorTable::getAnchor(const LEReferenceTo<Format3AnchorTable> &base, const LEFontInstance *fontInstance,110LEPoint &anchor, LEErrorCode &success) const111{112le_int16 x = SWAPW(xCoordinate);113le_int16 y = SWAPW(yCoordinate);114LEPoint pixels;115Offset dtxOffset = SWAPW(xDeviceTableOffset);116Offset dtyOffset = SWAPW(yDeviceTableOffset);117118fontInstance->transformFunits(x, y, pixels);119120if (dtxOffset != 0) {121LEReferenceTo<DeviceTable> dt(base, success, dtxOffset);122if (LE_SUCCESS(success)) {123le_int16 adjx = dt->getAdjustment(dt, (le_int16) fontInstance->getXPixelsPerEm(), success);124pixels.fX += adjx;125}126}127128if (dtyOffset != 0) {129LEReferenceTo<DeviceTable> dt(base, success, dtyOffset);130if (LE_SUCCESS(success)) {131le_int16 adjy = dt->getAdjustment(dt, (le_int16) fontInstance->getYPixelsPerEm(), success);132pixels.fY += adjy;133}134}135136fontInstance->pixelsToUnits(pixels, anchor);137}138139U_NAMESPACE_END140141142143