Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/font/layout/GlyphPositionAdjustments.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 "GlyphPositionAdjustments.h"33#include "LEGlyphStorage.h"34#include "LEFontInstance.h"3536U_NAMESPACE_BEGIN3738#define CHECK_ALLOCATE_ARRAY(array, type, size) \39if (array == NULL) { \40array = (type *) new type[size]; \41}4243GlyphPositionAdjustments::GlyphPositionAdjustments(le_int32 glyphCount)44: fGlyphCount(glyphCount), fEntryExitPoints(NULL), fAdjustments(NULL)45{46fAdjustments = (Adjustment *) new Adjustment[glyphCount];47}4849GlyphPositionAdjustments::~GlyphPositionAdjustments()50{51delete[] fEntryExitPoints;52delete[] fAdjustments;53}5455const LEPoint *GlyphPositionAdjustments::getEntryPoint(le_int32 index, LEPoint &entryPoint) const56{57if (fEntryExitPoints == NULL) {58return NULL;59}6061return fEntryExitPoints[index].getEntryPoint(entryPoint);62}6364const LEPoint *GlyphPositionAdjustments::getExitPoint(le_int32 index, LEPoint &exitPoint)const65{66if (fEntryExitPoints == NULL) {67return NULL;68}6970return fEntryExitPoints[index].getExitPoint(exitPoint);71}7273void GlyphPositionAdjustments::clearEntryPoint(le_int32 index)74{75CHECK_ALLOCATE_ARRAY(fEntryExitPoints, EntryExitPoint, fGlyphCount);7677fEntryExitPoints[index].clearEntryPoint();78}7980void GlyphPositionAdjustments::clearExitPoint(le_int32 index)81{82CHECK_ALLOCATE_ARRAY(fEntryExitPoints, EntryExitPoint, fGlyphCount);8384fEntryExitPoints[index].clearExitPoint();85}8687void GlyphPositionAdjustments::setEntryPoint(le_int32 index, LEPoint &newEntryPoint, le_bool baselineIsLogicalEnd)88{89CHECK_ALLOCATE_ARRAY(fEntryExitPoints, EntryExitPoint, fGlyphCount);9091fEntryExitPoints[index].setEntryPoint(newEntryPoint, baselineIsLogicalEnd);92}9394void GlyphPositionAdjustments::setExitPoint(le_int32 index, LEPoint &newExitPoint, le_bool baselineIsLogicalEnd)95{96CHECK_ALLOCATE_ARRAY(fEntryExitPoints, EntryExitPoint, fGlyphCount);9798fEntryExitPoints[index].setExitPoint(newExitPoint, baselineIsLogicalEnd);99}100101void GlyphPositionAdjustments::setCursiveGlyph(le_int32 index, le_bool baselineIsLogicalEnd)102{103CHECK_ALLOCATE_ARRAY(fEntryExitPoints, EntryExitPoint, fGlyphCount);104105fEntryExitPoints[index].setCursiveGlyph(baselineIsLogicalEnd);106}107108void GlyphPositionAdjustments::applyCursiveAdjustments(LEGlyphStorage &glyphStorage, le_bool rightToLeft, const LEFontInstance *fontInstance)109{110if (! hasCursiveGlyphs()) {111return;112}113114le_int32 start = 0, end = fGlyphCount, dir = 1;115le_int32 firstExitPoint = -1, lastExitPoint = -1;116LEPoint entryAnchor, exitAnchor, pixels;117LEGlyphID lastExitGlyphID = 0;118float baselineAdjustment = 0;119120// This removes a possible warning about121// using exitAnchor before it's been initialized.122exitAnchor.fX = exitAnchor.fY = 0;123124if (rightToLeft) {125start = fGlyphCount - 1;126end = -1;127dir = -1;128}129130for (le_int32 i = start; i != end; i += dir) {131LEGlyphID glyphID = glyphStorage[i];132133if (isCursiveGlyph(i)) {134if (lastExitPoint >= 0 && getEntryPoint(i, entryAnchor) != NULL) {135float anchorDiffX = exitAnchor.fX - entryAnchor.fX;136float anchorDiffY = exitAnchor.fY - entryAnchor.fY;137138baselineAdjustment += anchorDiffY;139adjustYPlacement(i, baselineAdjustment);140141if (rightToLeft) {142LEPoint secondAdvance;143144fontInstance->getGlyphAdvance(glyphID, pixels);145fontInstance->pixelsToUnits(pixels, secondAdvance);146147adjustXAdvance(i, -(anchorDiffX + secondAdvance.fX));148} else {149LEPoint firstAdvance;150151fontInstance->getGlyphAdvance(lastExitGlyphID, pixels);152fontInstance->pixelsToUnits(pixels, firstAdvance);153154adjustXAdvance(lastExitPoint, anchorDiffX - firstAdvance.fX);155}156}157158lastExitPoint = i;159160if (getExitPoint(i, exitAnchor) != NULL) {161if (firstExitPoint < 0) {162firstExitPoint = i;163}164165lastExitGlyphID = glyphID;166} else {167if (baselineIsLogicalEnd(i) && firstExitPoint >= 0 && lastExitPoint >= 0) {168le_int32 limit = lastExitPoint /*+ dir*/;169LEPoint dummyAnchor;170171if (getEntryPoint(i, dummyAnchor) != NULL) {172limit += dir;173}174175for (le_int32 j = firstExitPoint; j != limit; j += dir) {176if (isCursiveGlyph(j)) {177adjustYPlacement(j, -baselineAdjustment);178}179}180}181182firstExitPoint = lastExitPoint = -1;183baselineAdjustment = 0;184}185}186}187}188189LEPoint *GlyphPositionAdjustments::EntryExitPoint::getEntryPoint(LEPoint &entryPoint) const190{191if (fFlags & EEF_HAS_ENTRY_POINT) {192entryPoint = fEntryPoint;193return &entryPoint;194}195196return NULL;197}198199LEPoint *GlyphPositionAdjustments::EntryExitPoint::getExitPoint(LEPoint &exitPoint) const200{201if (fFlags & EEF_HAS_EXIT_POINT) {202exitPoint = fExitPoint;203return &exitPoint;204}205206return NULL;207}208209U_NAMESPACE_END210211212