Merge from the pain train
[official-gcc.git] / libjava / gnu / java / awt / peer / gtk / GdkGlyphVector.java
blob29d38b5e3f4bb9a5436b59a5fbc937c7bd0c34e0
1 /* GdkGlyphVector.java -- Glyph vector object
2 Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.java.awt.peer.gtk;
41 import java.awt.Font;
42 import java.awt.Rectangle;
43 import java.awt.Shape;
44 import java.awt.font.FontRenderContext;
45 import java.awt.font.GlyphJustificationInfo;
46 import java.awt.font.GlyphMetrics;
47 import java.awt.font.GlyphVector;
48 import java.awt.geom.AffineTransform;
49 import java.awt.geom.Point2D;
50 import java.awt.geom.Rectangle2D;
52 public class GdkGlyphVector extends GlyphVector
55 /* We use a simple representation for glyph vectors here. Glyph i
56 * consumes 8 doubles:
58 * logical x: extents[ 10*i ]
59 * logical y: extents[ 10*i + 1 ]
60 * logical width: extents[ 10*i + 2 ]
61 * logical height: extents[ 10*i + 3 ]
63 * visual x: extents[ 10*i + 4 ]
64 * visual y: extents[ 10*i + 5 ]
65 * visual width: extents[ 10*i + 6 ]
66 * visual height: extents[ 10*i + 7 ]
68 * origin pos x: extents[ 10*i + 8 ]
69 * origin pos y: extents[ 10*i + 9 ]
71 * as well as one int, code[i], representing the glyph code in the font.
74 double [] extents;
75 int [] codes;
77 Font font;
78 FontRenderContext fontRenderContext;
80 Rectangle2D allLogical;
81 Rectangle2D allVisual;
83 public GdkGlyphVector(double[] extents, int[] codes, Font font, FontRenderContext frc)
85 this.extents = extents;
86 this.codes = codes;
87 this.font = font;
88 this.fontRenderContext = frc;
90 allLogical = new Rectangle2D.Double();
91 allVisual = new Rectangle2D.Double();
93 for (int i = 0; i < codes.length; ++i)
95 allLogical.add (new Rectangle2D.Double(extents[10*i ] + extents[10*i + 8],
96 extents[10*i + 1] + extents[10*i + 9],
97 extents[10*i + 2],
98 extents[10*i + 3]));
100 allVisual.add (new Rectangle2D.Double(extents[10*i + 4] + extents[10*i + 8],
101 extents[10*i + 5] + extents[10*i + 9],
102 extents[10*i + 6],
103 extents[10*i + 7]));
108 geometric notes:
110 the FRC contains a mapping from points -> pixels.
112 typographics points are typically 1/72 of an inch.
114 pixel displays are often around 72 dpi.
116 so the FRC can get away with using an identity transform on a screen,
117 often. behavior is documented by sun to fall back to an identity
118 transform if the internal transformation is null.
120 coordinates coming up from pango are expressed as floats -- in device
121 space, so basically pixels-with-fractional-bits -- derived from their
122 storage format in pango (1024ths of pixels).
124 it is not clear from the javadocs whether the results of methods like
125 getGlyphPositions ought to return coordinates in device space, or
126 "point" space, or what. for now I'm returning them in device space.
130 public double[] getExtents()
132 return extents;
135 public int[] getCodes()
137 return codes;
140 public Font getFont ()
142 return font;
145 public FontRenderContext getFontRenderContext ()
147 return fontRenderContext;
150 public int getGlyphCharIndex (int glyphIndex)
152 // FIXME: currently pango does not provide glyph-by-glyph
153 // reverse mapping information, so we assume a broken 1:1
154 // glyph model here. This is plainly wrong.
155 return glyphIndex;
158 public int[] getGlyphCharIndices (int beginGlyphIndex,
159 int numEntries,
160 int[] codeReturn)
162 int ix[] = codeReturn;
163 if (ix == null)
164 ix = new int[numEntries];
166 for (int i = 0; i < numEntries; i++)
167 ix[i] = getGlyphCharIndex (beginGlyphIndex + i);
168 return ix;
171 public int getGlyphCode (int glyphIndex)
173 return codes[glyphIndex];
176 public int[] getGlyphCodes (int beginGlyphIndex, int numEntries,
177 int[] codeReturn)
179 if (codeReturn == null)
180 codeReturn = new int[numEntries];
182 System.arraycopy(codes, beginGlyphIndex, codeReturn, 0, numEntries);
183 return codeReturn;
186 public Shape getGlyphLogicalBounds (int i)
188 return new Rectangle2D.Double (extents[8*i], extents[8*i + 1],
189 extents[8*i + 2], extents[8*i + 3]);
192 public GlyphMetrics getGlyphMetrics (int i)
194 // FIXME: pango does not yield vertical layout information at the
195 // moment.
197 boolean is_horizontal = true;
198 double advanceX = extents[8*i + 2]; // "logical width" == advanceX
199 double advanceY = 0;
201 return new GlyphMetrics (is_horizontal,
202 (float) advanceX, (float) advanceY,
203 (Rectangle2D) getGlyphVisualBounds(i),
204 GlyphMetrics.STANDARD);
207 public Shape getGlyphOutline (int glyphIndex)
209 throw new UnsupportedOperationException ();
212 public Shape getGlyphOutline (int glyphIndex, float x, float y)
214 throw new UnsupportedOperationException ();
217 public Rectangle getGlyphPixelBounds (int i,
218 FontRenderContext renderFRC,
219 float x, float y)
221 return new Rectangle((int) x, (int) y,
222 (int) extents[8*i + 6], (int) extents[8*i + 7]);
225 public Point2D getGlyphPosition (int i)
227 return new Point2D.Double (extents[10*i + 8],
228 extents[10*i + 9]);
231 public float[] getGlyphPositions (int beginGlyphIndex,
232 int numEntries,
233 float[] positionReturn)
235 float fx[] = positionReturn;
236 if (fx == null)
237 fx = new float[numEntries * 2];
239 for (int i = 0; i < numEntries; ++i)
241 fx[2*i ] = (float) extents[10*i + 8];
242 fx[2*i + 1] = (float) extents[10*i + 9];
244 return fx;
247 public AffineTransform getGlyphTransform (int glyphIndex)
249 // Glyphs don't have independent transforms in these simple glyph
250 // vectors; docs specify null is an ok return here.
251 return null;
254 public Shape getGlyphVisualBounds (int i)
256 return new Rectangle2D.Double(extents[8*i + 4], extents[8*i + 5],
257 extents[8*i + 6], extents[8*i + 7]);
260 public int getLayoutFlags ()
262 return 0;
265 public Rectangle2D getLogicalBounds ()
267 return allLogical;
270 public int getNumGlyphs ()
272 return codes.length;
275 public Shape getOutline ()
277 throw new UnsupportedOperationException ();
280 public Rectangle getPixelBounds (FontRenderContext renderFRC,
281 float x, float y)
283 return new Rectangle((int)x,
284 (int)y,
285 (int) allVisual.getWidth(),
286 (int) allVisual.getHeight());
289 public Rectangle2D getVisualBounds ()
291 return allVisual;
294 public void performDefaultLayout ()
298 public void setGlyphPosition (int i, Point2D newPos)
300 extents[8*i ] = newPos.getX();
301 extents[8*i + 1] = newPos.getY();
303 extents[8*i + 4] = newPos.getX();
304 extents[8*i + 5] = newPos.getY();
307 public void setGlyphTransform (int glyphIndex,
308 AffineTransform newTX)
310 // not yet.. maybe not ever?
311 throw new UnsupportedOperationException ();
314 public boolean equals(GlyphVector gv)
316 if (gv == null)
317 return false;
319 if (! (gv instanceof GdkGlyphVector))
320 return false;
322 GdkGlyphVector ggv = (GdkGlyphVector) gv;
324 if ((ggv.codes.length != this.codes.length)
325 || (ggv.extents.length != this.extents.length))
326 return false;
328 if ((ggv.font == null && this.font != null)
329 || (ggv.font != null && this.font == null)
330 || (!ggv.font.equals(this.font)))
331 return false;
333 if ((ggv.fontRenderContext == null && this.fontRenderContext != null)
334 || (ggv.fontRenderContext != null && this.fontRenderContext == null)
335 || (!ggv.fontRenderContext.equals(this.fontRenderContext)))
336 return false;
338 for (int i = 0; i < ggv.codes.length; ++i)
339 if (ggv.codes[i] != this.codes[i])
340 return false;
342 for (int i = 0; i < ggv.extents.length; ++i)
343 if (ggv.extents[i] != this.extents[i])
344 return false;
346 return true;
349 public GlyphJustificationInfo getGlyphJustificationInfo(int idx)
351 throw new UnsupportedOperationException ();
354 public Shape getOutline(float x, float y)
356 throw new UnsupportedOperationException ();