Skip to content

Commit c88ef9d

Browse files
committed
image/font issues; adds gradient filling
1 parent ae082f5 commit c88ef9d

File tree

12 files changed

+312
-169
lines changed

12 files changed

+312
-169
lines changed

sources/net.sf.j2s.java.core/src/java/awt/Font.java

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,44 @@
2828

2929
package java.awt;
3030

31+
import static sun.font.EAttribute.EBACKGROUND;
32+
import static sun.font.EAttribute.EBIDI_EMBEDDING;
33+
import static sun.font.EAttribute.ECHAR_REPLACEMENT;
34+
import static sun.font.EAttribute.EFAMILY;
35+
import static sun.font.EAttribute.EFONT;
36+
import static sun.font.EAttribute.EFOREGROUND;
37+
import static sun.font.EAttribute.EINPUT_METHOD_HIGHLIGHT;
38+
import static sun.font.EAttribute.EINPUT_METHOD_UNDERLINE;
39+
import static sun.font.EAttribute.EJUSTIFICATION;
40+
import static sun.font.EAttribute.EKERNING;
41+
import static sun.font.EAttribute.ELIGATURES;
42+
import static sun.font.EAttribute.ENUMERIC_SHAPING;
43+
import static sun.font.EAttribute.EPOSTURE;
44+
import static sun.font.EAttribute.ERUN_DIRECTION;
45+
import static sun.font.EAttribute.ESIZE;
46+
import static sun.font.EAttribute.ESTRIKETHROUGH;
47+
import static sun.font.EAttribute.ESUPERSCRIPT;
48+
import static sun.font.EAttribute.ESWAP_COLORS;
49+
import static sun.font.EAttribute.ETRACKING;
50+
import static sun.font.EAttribute.ETRANSFORM;
51+
import static sun.font.EAttribute.EUNDERLINE;
52+
import static sun.font.EAttribute.EWEIGHT;
53+
import static sun.font.EAttribute.EWIDTH;
54+
55+
import java.awt.font.FontRenderContext;
56+
import java.awt.font.LineMetrics;
57+
import java.awt.font.TextAttribute;
58+
import java.awt.font.TextLayout;
59+
import java.awt.geom.AffineTransform;
60+
import java.awt.geom.Point2D;
61+
import java.awt.geom.Rectangle2D;
62+
import java.text.AttributedCharacterIterator.Attribute;
63+
//import java.util.Hashtable;
64+
//import java.util.Locale;
65+
import java.text.CharacterIterator;
66+
import java.util.Hashtable;
67+
import java.util.Map;
68+
3169
import javajs.util.SB;
3270
import sun.font.AttributeMap;
3371
import sun.font.AttributeValues;
@@ -37,21 +75,6 @@
3775
import swingjs.JSFontMetrics;
3876
import swingjs.JSLineMetrics;
3977
import swingjs.JSToolkit;
40-
import java.text.AttributedCharacterIterator.Attribute;
41-
//import java.util.Hashtable;
42-
//import java.util.Locale;
43-
import java.text.CharacterIterator;
44-
import java.util.Hashtable;
45-
import java.util.Map;
46-
import java.awt.font.FontRenderContext;
47-
import java.awt.font.LineMetrics;
48-
import java.awt.font.TextAttribute;
49-
import java.awt.geom.AffineTransform;
50-
import java.awt.geom.Point2D;
51-
52-
import sun.font.AttributeValues;
53-
import static sun.font.EAttribute.*;
54-
import java.awt.geom.Rectangle2D;
5578

5679
/**
5780
* The <code>Font</code> class represents fonts, which are used to
@@ -1141,10 +1164,13 @@ public AffineTransform getTransform() {
11411164

11421165
return at;
11431166
}
1144-
11451167
return new AffineTransform();
11461168
}
11471169

1170+
public AffineTransform 秘getRawTransformOrNull() {
1171+
return (nonIdentityTx ? getAttributeValues().getTransform() : null);
1172+
}
1173+
11481174
// x = r^0 + r^1 + r^2... r^n
11491175
// rx = r^1 + r^2 + r^3... r^(n+1)
11501176
// x - rx = r^0 - r^(n+1)
@@ -2722,32 +2748,12 @@ protected void finalize() throws Throwable {
27222748
*/
27232749
}
27242750

2725-
private Map<String, LineMetrics> mapLineMetrics;
2726-
private LineMetrics getLineMetrics(String s) {
2727-
if (mapLineMetrics == null)
2728-
mapLineMetrics = new Hashtable<String, LineMetrics>();
2729-
LineMetrics lm = mapLineMetrics.get(s);
2730-
return (lm == null ? new JSLineMetrics(this, s) : lm);
2731-
}
2751+
// private Map<String, LineMetrics> mapLineMetrics;
2752+
// private LineMetrics getLineMetrics(String s) {
2753+
// if (mapLineMetrics == null)
2754+
// mapLineMetrics = new Hashtable<String, LineMetrics>();
2755+
// LineMetrics lm = mapLineMetrics.get(s);
2756+
// return (lm == null ? new JSLineMetrics(this, s) : lm);
2757+
// }
27322758

2733-
public LineMetrics getLineMetrics(CharacterIterator ci, int beginIndex, int limit, Object object) {
2734-
// TODO Auto-generated method stub
2735-
return null;
2736-
}
2737-
2738-
public LineMetrics getLineMetrics(char[] chars, int beginIndex, int limit, Object object) {
2739-
// TODO Auto-generated method stub
2740-
return null;
2741-
}
2742-
2743-
public LineMetrics getLineMetrics(String str, int beginIndex, int limit, Object object) {
2744-
// TODO Auto-generated method stub
2745-
return null;
2746-
}
2747-
2748-
public LineMetrics getLineMetrics(String str, Object object) {
2749-
// TODO Auto-generated method stub
2750-
return null;
2751-
}
2752-
27532759
}

sources/net.sf.j2s.java.core/src/java/awt/FontMetrics.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,10 @@ public Rectangle2D getStringBounds( char [] chars,
616616
// }
617617
//
618618
private FontRenderContext myFRC(Graphics context) {
619-
return null;
620619
// if (context instanceof Graphics2D) {
621620
// return ((Graphics2D)context).getFontRenderContext();
622621
// }
623-
// return DEFAULT_FRC;
622+
return DEFAULT_FRC;
624623
}
625624

626625

sources/net.sf.j2s.java.core/src/java/awt/Graphics2D.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.awt.image.RenderedImage;
3737
import java.awt.image.renderable.RenderableImage;
3838
import java.awt.font.FontRenderContext;
39+
import java.awt.font.GlyphVector;
3940
import java.text.AttributedCharacterIterator;
4041

4142
import java.util.Map;
@@ -754,33 +755,33 @@ public abstract void drawString(AttributedCharacterIterator iterator,
754755
public abstract void drawString(AttributedCharacterIterator iterator,
755756
float x, float y);
756757

757-
// /**
758-
// * Renders the text of the specified
759-
// * {@link GlyphVector} using
760-
// * the <code>Graphics2D</code> context's rendering attributes.
761-
// * The rendering attributes applied include the <code>Clip</code>,
762-
// * <code>Transform</code>, <code>Paint</code>, and
763-
// * <code>Composite</code> attributes. The <code>GlyphVector</code>
764-
// * specifies individual glyphs from a {@link Font}.
765-
// * The <code>GlyphVector</code> can also contain the glyph positions.
766-
// * This is the fastest way to render a set of characters to the
767-
// * screen.
768-
// * @param g the <code>GlyphVector</code> to be rendered
769-
// * @param x the x position in User Space where the glyphs should
770-
// * be rendered
771-
// * @param y the y position in User Space where the glyphs should
772-
// * be rendered
773-
// * @throws NullPointerException if <code>g</code> is <code>null</code>.
774-
// *
775-
// * @see java.awt.Font#createGlyphVector
776-
// * @see java.awt.font.GlyphVector
777-
// * @see #setPaint
778-
// * @see java.awt.Graphics#setColor
779-
// * @see #setTransform
780-
// * @see #setComposite
781-
// * @see #setClip
782-
// */
783-
// public abstract void drawGlyphVector(GlyphVector g, float x, float y);
758+
/**
759+
* Renders the text of the specified
760+
* {@link GlyphVector} using
761+
* the <code>Graphics2D</code> context's rendering attributes.
762+
* The rendering attributes applied include the <code>Clip</code>,
763+
* <code>Transform</code>, <code>Paint</code>, and
764+
* <code>Composite</code> attributes. The <code>GlyphVector</code>
765+
* specifies individual glyphs from a {@link Font}.
766+
* The <code>GlyphVector</code> can also contain the glyph positions.
767+
* This is the fastest way to render a set of characters to the
768+
* screen.
769+
* @param g the <code>GlyphVector</code> to be rendered
770+
* @param x the x position in User Space where the glyphs should
771+
* be rendered
772+
* @param y the y position in User Space where the glyphs should
773+
* be rendered
774+
* @throws NullPointerException if <code>g</code> is <code>null</code>.
775+
*
776+
* @see java.awt.Font#createGlyphVector
777+
* @see java.awt.font.GlyphVector
778+
* @see #setPaint
779+
* @see java.awt.Graphics#setColor
780+
* @see #setTransform
781+
* @see #setComposite
782+
* @see #setClip
783+
*/
784+
public abstract void drawGlyphVector(GlyphVector g, float x, float y);
784785

785786
/**
786787
* Fills the interior of a <code>Shape</code> using the settings of the

sources/net.sf.j2s.java.core/src/java/awt/PaintContext.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
package java.awt;
3030

31+
import java.awt.image.Raster;
3132

3233
/**
3334
* The <code>PaintContext</code> interface defines the encapsulated
@@ -61,22 +62,22 @@ public interface PaintContext {
6162
*/
6263
Object getColorModel();
6364

64-
// /**
65-
// * Returns a <code>Raster</code> containing the colors generated for
66-
// * the graphics operation.
67-
// * @param x the x coordinate of the area in device space
68-
// * for which colors are generated.
69-
// * @param y the y coordinate of the area in device space
70-
// * for which colors are generated.
71-
// * @param w the width of the area in device space
72-
// * @param h the height of the area in device space
73-
// * @return a <code>Raster</code> representing the specified
74-
// * rectangular area and containing the colors generated for
75-
// * the graphics operation.
76-
// */
77-
// Raster getRaster(int x,
78-
// int y,
79-
// int w,
80-
// int h);
65+
/**
66+
* Returns a <code>Raster</code> containing the colors generated for
67+
* the graphics operation.
68+
* @param x the x coordinate of the area in device space
69+
* for which colors are generated.
70+
* @param y the y coordinate of the area in device space
71+
* for which colors are generated.
72+
* @param w the width of the area in device space
73+
* @param h the height of the area in device space
74+
* @return a <code>Raster</code> representing the specified
75+
* rectangular area and containing the colors generated for
76+
* the graphics operation.
77+
*/
78+
Raster getRaster(int x,
79+
int y,
80+
int w,
81+
int h);
8182

8283
}

sources/net.sf.j2s.java.core/src/java/awt/font/TextLine.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,13 +770,13 @@ private float getComponentShift(int index) {
770770
}
771771

772772
public void draw(Graphics2D g2, float x, float y) {
773+
773774
if (lp == null) {
774775
for (int i = 0, n = 0; i < fComponents.length; i++, n += 2) {
775776
TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];
776777
tlc.draw(g2, locs[n] + x, locs[n+1] + y);
777778
}
778779
} else {
779-
AffineTransform oldTx = g2.getTransform();
780780
Point2D.Float pt = new Point2D.Float();
781781
for (int i = 0, n = 0; i < fComponents.length; i++, n += 2) {
782782
TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];
@@ -786,10 +786,11 @@ public void draw(Graphics2D g2, float x, float y) {
786786
AffineTransform at = tlc.getBaselineTransform();
787787

788788
if (at != null) {
789+
g2 = (Graphics2D) g2.create();
789790
g2.translate(pt.x - at.getTranslateX(), pt.y - at.getTranslateY());
790791
g2.transform(at);
791792
tlc.draw(g2, 0, 0);
792-
g2.setTransform(oldTx);
793+
g2.dispose();
793794
} else {
794795
tlc.draw(g2, pt.x, pt.y);
795796
}

sources/net.sf.j2s.java.core/src/java/awt/image/LookupOp.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ public final BufferedImage filter(BufferedImage src, BufferedImage dst) {
187187

188188
// if (ImagingLib.filter(this, src, dst) == null) {
189189
// Do it the slow way
190+
191+
// added 2002.02.24 PhET AbstractMediaButtons
192+
src.checkHavePixels();
193+
190194
WritableRaster srcRaster = src.getRaster();
191195
WritableRaster dstRaster = dst.getRaster();
192196

sources/net.sf.j2s.java.core/src/java/awt/image/RescaleOp.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ public final BufferedImage filter (BufferedImage src, BufferedImage dst) {
396396
//
397397
// Native BI rescale failed - convert to rasters
398398
//
399+
400+
// added 2002.02.24 PhET AbstractMediaButtons
401+
src.checkHavePixels();
402+
399403
WritableRaster srcRaster = src.getRaster();
400404
WritableRaster dstRaster = dst.getRaster();
401405

0 commit comments

Comments
 (0)