/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
*
* (C) Copyright IBM Corp. 1998-2003 - All Rights Reserved
*/
/**
* Default implementation of ExtendedTextLabel.
*/
// {jbr} I made this class package-private to keep the
// Decoration.Label API package-private.
/* public */
// caches
float[] charinfo;
/**
* Create from a TextSource.
*/
finishInit();
}
/**
* Create from a TextSource, optionally using cached data from oldLabel starting at the offset.
* If present oldLabel must have been created from a run of text that includes the text used in
* the new label. Start in source corresponds to logical character offset in oldLabel.
*/
// currently no optimization.
finishInit();
}
private void finishInit() {
} else {
charTX = new AffineTransform();
}
}
}
// TextLabel API
}
lb = createLogicalBounds();
}
}
public float getAdvance() {
lb = createLogicalBounds();
}
}
}
}
ab = createAlignBounds();
}
}
ib = createItalicBounds();
}
}
}
public boolean isSimple() {
}
return baseTX; // passing internal object, caller must not modify!
}
return getGV().getOutline(x, y);
}
return decorator.getOutline(this, x, y);
}
g.drawGlyphVector(getGV(), x, y);
}
decorator.drawTextAndDecorations(this, g, x, y);
}
/**
* The logical bounds extends from the origin of the glyphvector to the
* position at which a following glyphvector's origin should be placed.
* We always assume glyph vectors are rendered from left to right, so
* the origin is always to the left.
* <p> On a left-to-right run, combining marks and 'ligatured away'
* characters are to the right of their base characters. The charinfo
* array will record the character positions for these 'missing' characters
* as being at the origin+advance of the base glyph, with zero advance.
* (This is not necessarily the same as the glyph position, for example,
* an umlaut glyph may have a position to the left of this point, it depends
* on whether the font was designed so that such glyphs overhang to the left
* of their origin, or whether it presumes some kind of kerning to position
* the glyphs). Anyway, the left of the bounds is the origin of the first
* logical (leftmost) character, and the right is the origin + advance of the
* last logical (rightmost) character.
* <p> On a right-to-left run, these special characters are to the left
* of their base characters. Again, since 'glyph position' has been abstracted
* away, we can use the origin of the leftmost character, and the origin +
* advance of the rightmost character.
* <p> On a mixed run (hindi) we can't rely on the first logical character
* being the leftmost character. However we can again rely on the leftmost
* character origin and the rightmost character + advance.
*/
return getGV().getLogicalBounds();
}
return getGV().getVisualBounds();
}
/**
* Like createLogicalBounds except ignore leading and logically trailing white space.
* this assumes logically trailing whitespace is also visually trailing.
* Whitespace is anything that has a zero visual width, regardless of its advance.
* <p> We make the same simplifying assumptions as in createLogicalBounds, namely
* that we can rely on the charinfo to shield us from any glyph positioning oddities
* in the font that place the glyph for a character at other than the pos + advance
* of the character to its left. So we no longer need to skip chars with zero
* advance, as their bounds (right and left) are already correct.
*/
float[] info = getCharinfo();
float al = 0f;
float aw = 0f;
}
if (lineIsLTR) {
}
}
if (rn >= 0) {
int ln = 0;
}
}
/*
boolean lineIsLTR = source.lineIsLTR();
int rn = info.length - numvals;
while (rn > 0 && ((info[rn+advx] == 0) || (lineIsLTR && info[rn+visw] == 0))) {
rn -= numvals;
}
if (rn >= 0) {
int ln = 0;
while (ln < rn && ((info[ln+advx] == 0) || (!lineIsLTR && info[ln+visw] == 0))) {
ln += numvals;
}
al = Math.max(0f, info[ln+posx]);
aw = info[rn+posx] + info[rn+advx] - al;
}
*/
}
if (ia != 0) {
if (ia > 0) {
} else {
}
}
return new Rectangle2D.Float(l, t, r - l, b - t);
}
}
return gv;
}
return gv;
}
// ExtendedTextLabel API
public int getNumCharacters() {
}
return cm;
}
float[] charinfo = getCharinfo();
return 0f;
} else {
}
}
float[] charinfo = getCharinfo();
return 0f;
} else {
}
}
float[] charinfo = getCharinfo();
return 0f;
} else {
}
}
float[] charinfo = getCharinfo();
return new Rectangle2D.Float();
}
return new Rectangle2D.Float(
}
if (x != 0 || y != 0) {
}
return bounds;
}
if (index < 0) {
}
}
/*
public int hitTestChar(float x, float y) {
// !!! return index of char hit, for swing
// result is negative for trailing-edge hits
// no italics so no problem at margins.
// for now, ignore y since we assume horizontal text
// find non-combining char origin to right of x
float[] charinfo = getCharinfo();
int n = 0;
int e = source.getLength();
while (n < e && charinfo[n + advx] != 0 && charinfo[n + posx] > x) {
n += numvals;
}
float rightx = n < e ? charinfo[n+posx] : charinfo[e - numvals + posx] + charinfo[e - numvals + advx];
// find non-combining char to left of that char
n -= numvals;
while (n >= 0 && charinfo[n+advx] == 0) {
n -= numvals;
}
float leftx = n >= 0 ? charinfo[n+posx] : 0;
float lefta = n >= 0 ? charinfo[n+advx] : 0;
n /= numvals;
boolean left = true;
if (x < leftx + lefta / 2f) {
// left of prev char
} else if (x < (leftx + lefta + rightx) / 2f) {
// right of prev char
left = false;
} else {
// left of follow char
n += 1;
}
if ((source.getLayoutFlags() & 0x1) != 0) {
n = getNumCharacters() - 1 - n;
left = !left;
}
return left ? n : -n;
}
*/
return l2v(logicalIndex);
}
return v2l(visualIndex);
}
float[] charinfo = getCharinfo();
--start;
break; // layout bailed for some reason
}
}
return start;
}
float a = 0f;
float[] charinfo = getCharinfo();
--start;
break; // layout bailed for some reason
}
}
return a;
}
// REMIND: improve this implementation
// Ligature formation can either be done in logical order,
// with the ligature glyph logically preceding the null
// chars; or in visual order, with the ligature glyph to
// the left of the null chars. This method's implementation
// must reflect which strategy is used.
return true;
}
if (c == '\t' || c == '\n' || c == '\r') { // hack
return true;
}
// If ligatures are always to the left, do this stuff:
//if (!(source.getLayoutFlags() & 0x1) == 0) {
// v += 1;
// if (v == source.getLength()) {
// return true;
// }
//}
float[] charinfo = getCharinfo();
return false;
} else {
}
}
private final float[] getCharinfo() {
charinfo = createCharinfo();
}
return charinfo;
}
/*
* This takes the glyph info record obtained from the glyph vector and converts it into a similar record
* adjusted to represent character data instead. For economy we don't use glyph info records in this processing.
*
* Here are some constraints:
* - there can be more glyphs than characters (glyph insertion, perhaps based on normalization, has taken place)
* - there can not be fewer glyphs than characters (0xffff glyphs are inserted for characters ligaturized away)
* - each glyph maps to a single character, when multiple glyphs exist for a character they all map to it, but
* no two characters map to the same glyph
* - multiple glyphs mapping to the same character need not be in sequence (thai, tamil have split characters)
* - glyphs may be arbitrarily reordered (Indic reorders glyphs)
* - all glyphs share the same bidi level
* - all glyphs share the same horizontal (or vertical) baseline
* - combining marks visually follow their base character in the glyph array-- i.e. in an rtl gv they are
* to the left of their base character-- and have zero advance.
*
* The output maps this to character positions, and therefore caret positions, via the following assumptions:
* - zero-advance glyphs do not contribute to the advance of their character (i.e. position is ignored), conversely
* if a glyph is to contribute to the advance of its character it must have a non-zero (float) advance
* - no carets can appear between a zero width character and its preceeding character, where 'preceeding' is
* defined logically.
* - no carets can appear within a split character
* - no carets can appear within a local reordering (i.e. Indic reordering, or non-adjacent split characters)
* - all characters lie on the same baseline, and it is either horizontal or vertical
* - the charinfo is in uniform ltr or rtl order (visual order), since local reorderings and split characters are removed
*
* The algorithm works in the following way:
* 1) we scan the glyphs ltr or rtl based on the bidi run direction
* 2) we can work in place, since we always consume a glyph for each char we write
* a) if the line is ltr, we start writing at position 0 until we finish, there may be leftver space
* b) if the line is rtl and 1-1, we start writing at position numChars/glyphs - 1 until we finish at 0
* c) otherwise if we don't finish at 0, we have to copy the data down
* 3) we consume clusters in the following way:
* a) the first element is always consumed
* b) subsequent elements are consumed if:
* i) their advance is zero
* ii) their character index <= the character index of any character seen in this cluster
* iii) the minimum character index seen in this cluster isn't adjacent to the previous cluster
* c) character data is written as follows for horizontal lines (x/y and w/h are exchanged on vertical lines)
* i) the x position is the position of the leftmost glyph whose advance is not zero
* ii)the y position is the baseline
* iii) the x advance is the distance to the maximum x + adv of all glyphs whose advance is not zero
* iv) the y advance is the baseline
* v) vis x,y,w,h tightly encloses the vis x,y,w,h of all the glyphs with nonzero w and h
* 4) we can make some simple optimizations if we know some things:
* a) if the mapping is 1-1, unidirectional, and there are no zero-adv glyphs, we just return the glyphinfo
* b) if the mapping is 1-1, unidirectional, we just adjust the remaining glyphs to originate at right/left of the base
* c) if the mapping is 1-1, we compute the base position and advance as we go, then go back to adjust the remaining glyphs
* d) otherwise we keep separate track of the write position as we do (c) since no glyph in the cluster may be in the
* position we are writing.
* e) most clusters are simply the single base glyph in the same position as its character, so we try to avoid
* copying its data unnecessarily.
* 5) the glyph vector ought to provide access to these 'global' attributes to enable these optimizations. A single
* int with flags set is probably ok, we could also provide accessors for each attribute. This doesn't map to
* the GlyphMetrics flags very well, so I won't attempt to keep them similar. It might be useful to add those
* in addition to these.
* int FLAG_HAS_ZERO_ADVANCE_GLYPHS = 1; // set if there are zero-advance glyphs
* int FLAG_HAS_NONUNIFORM_ORDER = 2; // set if some glyphs are rearranged out of character visual order
* int FLAG_HAS_SPLIT_CHARACTERS = 4; // set if multiple glyphs per character
* int getDescriptionFlags(); // return an int containing the above flags
* boolean hasZeroAdvanceGlyphs();
* boolean hasNonuniformOrder();
* boolean hasSplitCharacters();
* The optimized cases in (4) correspond to values 0, 1, 3, and 7 returned by getDescriptionFlags().
*/
protected float[] createCharinfo() {
try {
}
catch (Exception e) {
}
/*
if ((gv.getDescriptionFlags() & 0x7) == 0) {
return glyphinfo;
}
*/
if (numGlyphs == 0) {
return glyphinfo;
}
boolean DEBUG = false;
if (DEBUG) {
for (int i = 0; i < numGlyphs; ++i) {
", n: " + indices[i]);
}
}
if (!ltr) {
gxlimit = -1;
xdelta = -1;
}
/*
// to support vertical, use 'ixxxx' indices and swap horiz and vertical components
if (source.isVertical()) {
iposx = posy;
iposy = posx;
iadvx = advy;
iadvy = advx;
ivisx = visy;
ivisy = visx;
ivish = visw;
ivisw = vish;
} else {
// use standard values
}
*/
// use intermediates to reduce array access when we need to
float baseline = 0;
// record if we have to copy data even when no cluster
boolean mustCopy = false;
// start of new cluster
boolean haveCopy = false;
int clusterExtraGlyphs = 0;
// advance to next glyph
/*
while (gx != gxlimit && (glyphinfo[gp + advx] == 0 ||
minIndex != nextMin || indices[gx] <= maxIndex)) {
*/
// initialize base data first time through, using base glyph
if (!haveCopy) {
haveCopy = true;
}
// have an extra glyph in this cluster
// adjust advance only if new glyph has non-zero advance
if (radvx != 0) {
}
// adjust visible bounds only if new glyph has non-empty bounds
if (rvisw != 0) {
}
// adjust min, max index
// get ready to examine next glyph
}
// done with cluster, gx and gp are set for next glyph
if (DEBUG) {
}
// do common character adjustments
if (haveCopy) {
// save adjustments to the base character
// compare number of chars read with number of glyphs read.
// if more glyphs than chars, set mustCopy to true, as we'll always have
// to copy the data from here on out.
mustCopy = true;
}
// Fix the characters that follow the base character.
// New values are all the same. Note we fix the number of characters
// we saw, not the number of glyphs we saw.
if (!ltr) {
// if rtl, characters to left of base, else to right. reuse cposr.
}
++minIndex;
if (DEBUG) System.out.println("minIndex = " + iMinIndex + ", maxIndex = " + maxIndex + ", cp = " + icp);
}
}
}
// no longer using this copy
haveCopy = false;
} else if (mustCopy) {
// out of synch, so we have to copy all the time now
}
// else glyphinfo is already at the correct character position, and is unchanged, so just leave it
// reset for new cluster
}
// data written to wrong end of array, need to shift down
}
if (DEBUG) {
" x: " + glyphinfo[i++] +
" y: " + glyphinfo[i++] +
" xa: " + glyphinfo[i++] +
" ya: " + glyphinfo[i++] +
" l: " + glyphinfo[i++] +
" t: " + glyphinfo[i++] +
" w: " + glyphinfo[i++] +
" h: " + glyphinfo[i++]);
}
}
return glyphinfo;
}
/**
* Map logical character index to visual character index.
* <p>
* This ignores hindi reordering. @see createCharinfo
*/
}
/**
* Map visual character index to logical character index.
* <p>
* This ignores hindi reordering. @see createCharinfo
*/
}
}
if (true) {
}
} else {
}
}
}
//public static ExtendedTextLabel create(TextSource source) {
// return new ExtendedTextSourceLabel(source);
//}
public int getNumJustificationInfos() {
return getGV().getNumGlyphs();
}
public void getJustificationInfos(GlyphJustificationInfo[] infos, int infoStart, int charStart, int charLimit) {
// This simple implementation only uses spaces for justification.
// Since regular characters aren't justified, we don't need to deal with
// special infos for combining marks or ligature substitution glyphs.
// added character justification for kanjii only 2/22/98
float[] charinfo = getCharinfo();
new GlyphJustificationInfo(0,
// assume data is 1-1 and either all rtl or all ltr, for now
int minGlyph = 0;
if (ltr) {
} else {
}
}
for (int i = 0; i < numGlyphs; ++i) {
} else {
if (Character.isWhitespace(c)) {
// CJK, Hangul, CJK Compatibility areas
} else if (c >= 0x4e00 &&
(c < 0xa000) ||
(c >= 0xac00 && c < 0xd7b0) ||
(c >= 0xf900 && c < 0xfb00)) {
} else {
}
}
}
}
}
public TextLineComponent applyJustificationDeltas(float[] deltas, int deltaStart, boolean[] flags) {
// when we justify, we need to adjust the charinfo since spaces
// change their advances. preserve the existing charinfo.
// we only push spaces, so never need to rejustify
flags[0] = false;
// preserve the existing gv.
/*
System.out.println("oldgv: " + getGV() + ", newgv: " + newgv);
System.out.println("newpositions: " + newPositions);
for (int i = 0; i < newPositions.length; i += 2) {
System.out.println("[" + (i/2) + "] " + newPositions[i] + ", " + newPositions[i+1]);
}
System.out.println("deltas: " + deltas + " start: " + deltaStart);
for (int i = deltaStart; i < deltaStart + numGlyphs; i += 2) {
System.out.println("[" + (i/2) + "] " + deltas[i] + ", " + deltas[i+1]);
}
*/
// accumulate the deltas to adjust positions and advances.
// handle whitespace by modifying advance,
// handle everything else by modifying position before and after
float deltaPos = 0;
for (int i = 0; i < numGlyphs; ++i) {
} else {
}
}
/*
newPositions = newgv.getGlyphPositions(null);
System.out.println(">> newpositions: " + newPositions);
for (int i = 0; i < newPositions.length; i += 2) {
System.out.println("[" + (i/2) + "] " + newPositions[i] + ", " + newPositions[i+1]);
}
*/
return result;
}
}