Replace the GNU ClasspathToolkit with the SunToolkit in .NET Code. Replace the usage of the FontPeer with the Java2D. Replace the NetGlyphVector with the StandardGlyphVector

This commit is contained in:
smallsql 2009-05-16 16:34:40 +00:00
Родитель b8e96f6bd1
Коммит fccc39b788
11 изменённых файлов: 2829 добавлений и 1360 удалений

Просмотреть файл

@ -1,7 +1,7 @@
/*
Copyright (C) 2002, 2004, 2005, 2006, 2007 Jeroen Frijters
Copyright (C) 2006 Active Endpoints, Inc.
Copyright (C) 2006, 2007 Volker Berlin
Copyright (C) 2006, 2007, 2009 Volker Berlin
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -41,16 +41,14 @@ namespace ikvm.awt
class NetFontMetrics : java.awt.FontMetrics
{
private readonly NetFontPeer peer;
public NetFontMetrics(java.awt.Font font) : base(font)
{
peer = (NetFontPeer)font.getPeer();
}
private Font GetNetFont()
{
return peer.netFont;
return font.getNetFont();
}
public override int getHeight()
@ -165,7 +163,7 @@ namespace ikvm.awt
}
}
class NetFontPeer : gnu.java.awt.peer.ClasspathFontPeer, IDisposable
/* class NetFontPeer : java.awt.peer.FontPeer, IDisposable
{
internal readonly Font netFont;
@ -175,7 +173,7 @@ namespace ikvm.awt
netFont = J2C.ConvertFont(name, getStyle(null), getSize(null));
}
public override bool canDisplay(java.awt.Font font, char param2)
public override bool canDisplay(int codePoint)
{
//HACK There is no equivalent in C# http://msdn2.microsoft.com/en-us/library/sf4dhbw8(VS.80).aspx
return true;
@ -291,7 +289,7 @@ namespace ikvm.awt
}
#endregion
}
}*/
class NetGlyphVector : GlyphVector
{

Просмотреть файл

@ -1,7 +1,7 @@
/*
Copyright (C) 2002, 2004, 2005, 2006, 2007 Jeroen Frijters
Copyright (C) 2006 Active Endpoints, Inc.
Copyright (C) 2006, 2007, 2008 Volker Berlin (i-net software)
Copyright (C) 2006, 2007, 2008, 2009 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -104,7 +104,7 @@ namespace ikvm.awt
font = new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12);
}
this.font = font;
netfont = ((NetFontPeer)font.getPeer()).netFont;
netfont = font.getNetFont();
this.color = fgcolor;
this.bgcolor = bgcolor;
init(g);
@ -531,7 +531,7 @@ namespace ikvm.awt
// TODO why is Component calling us with a null reference and is this legal?
if (f != null)
{
netfont = ((NetFontPeer)f.getPeer()).netFont;
netfont = font.getNetFont();
font = f;
}
else

Просмотреть файл

@ -1419,7 +1419,7 @@ namespace ikvm.awt
private void setFontImpl(java.awt.Font font)
{
control.Font = ((NetFontPeer)font.getPeer()).netFont;
control.Font = font.getNetFont();
}
public void setFont(java.awt.Font font)

Просмотреть файл

@ -4,7 +4,6 @@
../../classpath-0.95/gnu/java/awt/BitwiseXORComposite.java
../../classpath-0.95/gnu/java/awt/Buffers.java
../../classpath-0.95/gnu/java/awt/ClasspathGraphicsEnvironment.java
../../classpath-0.95/gnu/java/awt/ClasspathToolkit.java
../../classpath-0.95/gnu/java/awt/color/CieXyzConverter.java
../../classpath-0.95/gnu/java/awt/color/ClutProfileConverter.java
../../classpath-0.95/gnu/java/awt/color/ColorLookUpTable.java
@ -20,7 +19,6 @@
../../classpath-0.95/gnu/java/awt/color/ToneReproductionCurve.java
../../classpath-0.95/gnu/java/awt/ComponentDataBlitOp.java
../../classpath-0.95/gnu/java/awt/ComponentReshapeEvent.java
../../classpath-0.95/gnu/java/awt/EmbeddedWindow.java
../../classpath-0.95/gnu/java/awt/EventModifier.java
../../classpath-0.95/gnu/java/awt/GradientPaintContext.java
../../classpath-0.95/gnu/java/awt/image/ImageDecoder.java
@ -41,7 +39,6 @@
../../classpath-0.95/gnu/java/awt/java2d/ShapeCache.java
../../classpath-0.95/gnu/java/awt/java2d/TexturePaintContext.java
../../classpath-0.95/gnu/java/awt/LowPriorityEvent.java
../../classpath-0.95/gnu/java/awt/peer/ClasspathFontPeer.java
../../classpath-0.95/gnu/java/awt/peer/EmbeddedWindowPeer.java
../../classpath-0.95/gnu/java/awt/peer/headless/HeadlessGraphicsEnvironment.java
../../classpath-0.95/gnu/java/awt/peer/NativeEventLoopRunningEvent.java

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -23,6 +23,9 @@
*/
package sun.font;
import cli.System.Drawing.Font;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
/**
@ -30,4 +33,14 @@ package sun.font;
*/
public class CompositeFont extends Font2D{
@Override
public int getStyle(){
throw new NotImplementedException();
}
@Override
public Font createNetFont(java.awt.Font font){
throw new NotImplementedException();
}
}

Просмотреть файл

@ -25,6 +25,8 @@ package sun.font;
import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.util.Locale;
@ -33,6 +35,77 @@ import java.awt.font.FontRenderContext;
*/
public abstract class Font2D{
/* SunGraphics2D has font, tx, aa and fm. From this info
* can get a Strike object from the cache, creating it if necessary.
* This code is designed for multi-threaded access.
* For that reason it creates a local FontStrikeDesc rather than filling
* in a shared one. Up to two AffineTransforms and one FontStrikeDesc will
* be created by every lookup. This appears to perform more than
* adequately. But it may make sense to expose FontStrikeDesc
* as a parameter so a caller can use its own.
* In such a case if a FontStrikeDesc is stored as a key then
* we would need to use a private copy.
*
* Note that this code doesn't prevent two threads from creating
* two different FontStrike instances and having one of the threads
* overwrite the other in the map. This is likely to be a rare
* occurrence and the only consequence is that these callers will have
* different instances of the strike, and there'd be some duplication of
* population of the strikes. However since users of these strikes are
* transient, then the one that was overwritten would soon be freed.
* If there is any problem then a small synchronized block would be
* required with its attendant consequences for MP scaleability.
*/
public FontStrike getStrike(Font font, AffineTransform devTx,
int aa, int fm) {
return getStrike(font, null);
}
public FontStrike getStrike(Font font, FontRenderContext frc) {
// TODO Auto-generated method stub
return null;
}
public void removeFromCache(FontStrikeDesc desc){
// TODO Auto-generated method stub
}
/**
* The length of the metrics array must be >= 8. This method will
* store the following elements in that array before returning:
* metrics[0]: ascent
* metrics[1]: descent
* metrics[2]: leading
* metrics[3]: max advance
* metrics[4]: strikethrough offset
* metrics[5]: strikethrough thickness
* metrics[6]: underline offset
* metrics[7]: underline thickness
*/
public void getFontMetrics(Font font, AffineTransform identityTx, Object antiAliasingHint,
Object fractionalMetricsHint, float[] metrics){
// TODO Auto-generated method stub
}
/**
* The length of the metrics array must be >= 4. This method will
* store the following elements in that array before returning:
* metrics[0]: ascent
* metrics[1]: descent
* metrics[2]: leading
* metrics[3]: max advance
*/
public void getFontMetrics(Font font, FontRenderContext frc,
float metrics[]) {
StrikeMetrics strikeMetrics = getStrike(font, frc).getFontMetrics();
metrics[0] = strikeMetrics.getAscent();
metrics[1] = strikeMetrics.getDescent();
metrics[2] = strikeMetrics.getLeading();
metrics[3] = strikeMetrics.getMaxAdvance();
}
/*
* All the important subclasses override this which is principally for
* the TrueType 'gasp' table.
@ -45,14 +118,71 @@ public abstract class Font2D{
return false;
}
public void removeFromCache(FontStrikeDesc desc){
// TODO Auto-generated method stub
}
public FontStrike getStrike(Font font, FontRenderContext frc){
/* The following methods implement public methods on java.awt.Font */
public String getPostscriptName(){
// TODO Auto-generated method stub
return null;
}
public String getFontName(Locale l){
// TODO Auto-generated method stub
return null;
}
public String getFamilyName(Locale l){
// TODO Auto-generated method stub
return null;
}
public int getNumGlyphs(){
// TODO Auto-generated method stub
return 0;
}
public int getMissingGlyphCode(){
// TODO Auto-generated method stub
return 0;
}
public boolean canDisplay(char c){
//HACK There is no equivalent in C# http://msdn2.microsoft.com/en-us/library/sf4dhbw8(VS.80).aspx
return true;
}
public boolean canDisplay(int cp){
//HACK There is no equivalent in C# http://msdn2.microsoft.com/en-us/library/sf4dhbw8(VS.80).aspx
return true;
}
public byte getBaselineFor(char c) {
return Font.ROMAN_BASELINE;
}
public float getItalicAngle(Font font, AffineTransform at,
Object aaHint, Object fmHint) {
/* hardwire psz=12 as that's typical and AA vs non-AA for 'gasp' mode
* isn't important for the caret slope of this rarely used API.
*/
int aa = FontStrikeDesc.getAAHintIntVal(aaHint, this, 12);
int fm = FontStrikeDesc.getFMHintIntVal(fmHint);
FontStrike strike = getStrike(font, at, aa, fm);
StrikeMetrics metrics = strike.getFontMetrics();
if (metrics.ascentY == 0 || metrics.ascentX == 0) {
return 0f;
} else {
/* ascent is "up" from the baseline so its typically
* a negative value, so we need to compensate
*/
return metrics.ascentX/-metrics.ascentY;
}
}
/** Returns the "real" style of this Font2D. Eg the font face
* Lucida Sans Bold" has a real style of Font.BOLD, even though
* it may be able to used to simulate bold italic
*/
public abstract int getStyle();
public abstract cli.System.Drawing.Font createNetFont(Font font);
}

Просмотреть файл

@ -27,6 +27,12 @@ import ikvm.awt.IkvmToolkit;
import java.awt.Font;
import java.awt.Toolkit;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
@ -35,8 +41,73 @@ import java.awt.Toolkit;
*/
public class FontManager{
public static final int NO_FALLBACK = 0;
public static final int PHYSICAL_FALLBACK = 1;
public static final int LOGICAL_FALLBACK = 2;
private static ConcurrentHashMap<String, Font2D> fontNameCache = new ConcurrentHashMap<String, Font2D>();
private static final Method getFont2D;
static{
try{
getFont2D = Font.class.getDeclaredMethod("getFont2D");
getFont2D.setAccessible(true);
}catch(NoSuchMethodException ex){
NoClassDefFoundError error = new NoClassDefFoundError(ex.toString());
error.initCause(ex);
throw error;
}
}
/**
* return String representation of style prepended with "."
* This is useful for performance to avoid unnecessary string operations.
*/
private static String dotStyleStr(int num) {
switch(num){
case Font.BOLD:
return ".bold";
case Font.ITALIC:
return ".italic";
case Font.ITALIC | Font.BOLD:
return ".bolditalic";
default:
return ".plain";
}
}
/**
* The client supplies a name and a style.
* The name could be a family name, or a full name.
* A font may exist with the specified style, or it may
* exist only in some other style. For non-native fonts the scaler
* may be able to emulate the required style.
*/
public static Font2D findFont2D(String name, int style, int fallback){
String lowerCaseName = name.toLowerCase(Locale.ENGLISH);
String mapName = lowerCaseName + dotStyleStr(style);
Font2D font2D = fontNameCache.get(mapName);
if(font2D != null){
return font2D;
}
font2D = new PhysicalFont(name,style);
fontNameCache.put(mapName, font2D);
return font2D;
}
/** This method can be more efficient as it will only need to
* do the lookup once, and subsequent calls on the java.awt.Font
* instance can utilize the cached Font2D on that object.
* Its unfortunate it needs to be a native method, but the font2D
* variable has to be private.
*/
public static Font2D getFont2D(Font font){
return new PhysicalFont(font);
try{
return (Font2D)getFont2D.invoke(font);
}catch(Exception ex){
throw new RuntimeException(ex);
}
}
public static boolean isComplexText(char[] text, int start, int limit){
@ -60,8 +131,7 @@ public class FontManager{
}
public static Font getCompositeFontUIResource(Font f){
// TODO Auto-generated method stub
return null;
throw new NotImplementedException();
}
public static boolean registerFont(Font font){
@ -84,4 +154,8 @@ public class FontManager{
return false;
}
public static Font2D getNewComposite(Object object, int style, Font2D font2D){
throw new NotImplementedException();
}
}

Просмотреть файл

@ -26,31 +26,108 @@ package sun.font;
import java.awt.Font;
import java.awt.font.FontRenderContext;
import cli.System.Drawing.FontFamily;
import cli.System.Drawing.FontStyle;
/**
* A Font2D implementation that based on .NET fonts.
* It replace the equals naming Sun class.
* A Font2D implementation that based on .NET fonts. It replace the equals naming Sun class.
* A Font2D is define with the font name and the font style but it is independent of the size;
*/
class PhysicalFont extends Font2D{
private final Font font;
private final FontFamily family;
private final FontStyle style;
private static final FontStyle REGULAR = FontStyle.wrap(FontStyle.Regular);
private static final FontStyle BOLD = FontStyle.wrap(FontStyle.Bold);
private static final FontStyle ITALIC = FontStyle.wrap(FontStyle.Italic);
private static final FontStyle BOLD_ITALIC = FontStyle.wrap(FontStyle.Bold + FontStyle.Italic);
private static final cli.System.Drawing.GraphicsUnit PIXEL = cli.System.Drawing.GraphicsUnit
.wrap(cli.System.Drawing.GraphicsUnit.Pixel);
private FontStrike strike;
PhysicalFont(Font font)
{
this.font = font;
PhysicalFont(String name, int style){
this.family = createFontFamily(name);
this.style = createFontStyle(family, style);
}
public cli.System.Drawing.Font createNetFont(Font font){
float size2D = font.getSize2D();
if(size2D <= 0){
size2D = 1;
}
return new cli.System.Drawing.Font(family, size2D, style, PIXEL);
}
private static FontFamily createFontFamily(String name){
if("monospaced".equalsIgnoreCase(name) || "courier".equalsIgnoreCase(name)){
return FontFamily.get_GenericMonospace();
}
if("serif".equalsIgnoreCase(name)){
return FontFamily.get_GenericSerif();
}
if(name == null || "sansserif".equalsIgnoreCase(name) || "dialog".equalsIgnoreCase(name)
|| "dialoginput".equalsIgnoreCase(name) || "default".equalsIgnoreCase(name)){
return FontFamily.get_GenericSansSerif();
}
try{
return new FontFamily(name);
}catch(Exception ex) // cli.System.ArgumentException
{
return FontFamily.get_GenericSansSerif();
}
}
private static FontStyle createFontStyle(FontFamily family, int style){
int fs = FontStyle.Regular;
if((style & java.awt.Font.BOLD) != 0){
fs |= FontStyle.Bold;
}
if((style & java.awt.Font.ITALIC) != 0){
fs |= FontStyle.Italic;
}
FontStyle fontStyle = FontStyle.wrap(fs);
if(!family.IsStyleAvailable(fontStyle)){
// Some Fonts (for example Aharoni) does not support Regular style. This throw an exception else it is not
// documented.
if(family.IsStyleAvailable(REGULAR)){
fontStyle = REGULAR;
}else if(family.IsStyleAvailable(BOLD)){
fontStyle = BOLD;
}else if(family.IsStyleAvailable(ITALIC)){
fontStyle = ITALIC;
}else if(family.IsStyleAvailable(BOLD_ITALIC)){
fontStyle = BOLD_ITALIC;
}
}
return fontStyle;
}
/**
* {@inheritDoc}
*/
@Override
public FontStrike getStrike(Font font, FontRenderContext frc){
if(strike == null){
strike = new PhysicalStrike(font);
strike = new PhysicalStrike(font.getSize2D(), family, style);
}
return strike;
}
@Override
public int getStyle(){
return style.Value;
}
}

Просмотреть файл

@ -23,14 +23,12 @@
*/
package sun.font;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.font.LineMetrics;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D.Float;
import java.text.StringCharacterIterator;
import cli.System.Drawing.FontFamily;
import cli.System.Drawing.FontStyle;
/**
* A FontStrike implementation that based on .NET fonts.
@ -38,12 +36,19 @@ import java.text.StringCharacterIterator;
*/
public class PhysicalStrike extends FontStrike{
private final Font font;
private final FontFamily family;
private final FontStyle style;
private final float size2D;
private final float factor;
private StrikeMetrics strike;
public PhysicalStrike(Font font){
this.font = font;
public PhysicalStrike(float size2D, FontFamily family, FontStyle style){
this.family = family;
this.style = style;
this.size2D = size2D;
factor = size2D / family.GetEmHeight(style);
}
/**
@ -72,14 +77,16 @@ public class PhysicalStrike extends FontStrike{
@Override
StrikeMetrics getFontMetrics(){
if(strike == null){
gnu.java.awt.peer.ClasspathFontPeer peer = (gnu.java.awt.peer.ClasspathFontPeer)font.getPeer();
LineMetrics metrics = peer.getLineMetrics(font, new StringCharacterIterator(""), 0, 0, null);
float ascent = family.GetCellAscent(style) * factor;
float descent = family.GetCellDescent(style) * factor;
float height = family.GetLineSpacing(style) * factor;
float leading = height - ascent - descent;
strike = new StrikeMetrics(
0, metrics.getAscent(),
0, metrics.getDescent(),
0, ascent,
0, descent,
0.25f, 0,
0, metrics.getLeading(),
font.getSize2D() * 2, 0);
0, leading,
size2D * 2, 0);
}
return strike;
}

Просмотреть файл

@ -23,61 +23,273 @@
*/
package sun.font;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphJustificationInfo;
import java.awt.font.GlyphMetrics;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.text.CharacterIterator;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
/**
* Standard implementation of GlyphVector used by Font, GlyphList, and SunGraphics2D.
*
*/
public class StandardGlyphVector extends GlyphVector{
private float[] positions; // only if not default advances
private final Font font;
private final FontRenderContext frc;
private final String glyphs;
private transient FontMetrics metrics;
public StandardGlyphVector(Font font, String str, FontRenderContext frc){
if(str == null){
throw new NullPointerException("Glyphs are null");
}
this.font = font;
this.frc = frc;
this.glyphs = str;
}
public StandardGlyphVector(Font font, CharacterIterator ci, FontRenderContext frc){
this(font, getString(ci), frc);
}
public StandardGlyphVector(Font font, int[] glyphCodes, FontRenderContext frc){
throw new NotImplementedException();
}
public StandardGlyphVector(Font font, char[] chars, FontRenderContext frc){
this(font, chars, 0, chars.length, frc);
}
public StandardGlyphVector(Font font, char[] chars, int beginIndex, int length, FontRenderContext frc){
this(font, new String(chars, beginIndex, length), frc);
}
/**
* Standard implementation of GlyphVector used by Font, GlyphList, and
* SunGraphics2D.
* Create and get
*
* @return
*/
public abstract class StandardGlyphVector extends GlyphVector{
private float[] positions; // only if not default advances
private FontMetrics getMetrics(){
if(metrics == null){
metrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
}
return metrics;
}
/**
* As a concrete subclass of GlyphVector, this must implement clone.
*/
@Override
public Object clone(){
try{
StandardGlyphVector result = (StandardGlyphVector)super.clone();
return result;
}
catch (CloneNotSupportedException e) {
}catch(CloneNotSupportedException e){
e.printStackTrace();
}
return this;
}
// ////////////////////
// StandardGlyphVector new public methods
// ///////////////////
/**
* Set all the glyph positions, including the 'after last glyph' position.
* The srcPositions array must be of length (numGlyphs + 1) * 2.
* Set all the glyph positions, including the 'after last glyph' position. The srcPositions array must be of length
* (numGlyphs + 1) * 2.
*/
public void setGlyphPositions(float[] srcPositions){
positions = (float[])srcPositions.clone();
positions = srcPositions.clone();
}
/**
* This is a convenience overload that gets all the glyph positions, which
* is what you usually want to do if you're getting more than one.
* !!! should I bother taking result parameter?
* This is a convenience overload that gets all the glyph positions, which is what you usually want to do if you're
* getting more than one. !!! should I bother taking result parameter?
*/
public float[] getGlyphPositions(float[] result){
return positions;
}
/**
* For each glyph return posx, posy, advx, advy, visx, visy, visw, vish.
*/
public float[] getGlyphInfo(){
throw new Error("getGlyphInfo is not implemented.");
throw new NotImplementedException();
}
@Override
public boolean equals(GlyphVector set){
throw new NotImplementedException();
}
@Override
public Font getFont(){
return font;
}
@Override
public FontRenderContext getFontRenderContext(){
return frc;
}
@Override
public int getGlyphCode(int glyphIndex){
throw new NotImplementedException();
}
@Override
public int[] getGlyphCodes(int beginGlyphIndex, int numEntries, int[] codeReturn){
throw new NotImplementedException();
}
@Override
public GlyphJustificationInfo getGlyphJustificationInfo(int glyphIndex){
throw new NotImplementedException();
}
@Override
public Shape getGlyphLogicalBounds(int glyphIndex){
throw new NotImplementedException();
}
@Override
public GlyphMetrics getGlyphMetrics(int glyphIndex){
throw new NotImplementedException();
}
@Override
public Shape getGlyphOutline(int glyphIndex){
throw new NotImplementedException();
}
@Override
public Point2D getGlyphPosition(int glyphIndex){
throw new NotImplementedException();
}
@Override
public float[] getGlyphPositions(int beginGlyphIndex, int numEntries, float[] positionReturn){
throw new NotImplementedException();
}
@Override
public AffineTransform getGlyphTransform(int glyphIndex){
throw new NotImplementedException();
}
@Override
public Shape getGlyphVisualBounds(int index){
return getMetrics().getStringBounds(glyphs.substring(index, index + 1), null);
}
@Override
public Rectangle2D getLogicalBounds(){
throw new NotImplementedException();
}
@Override
public int getNumGlyphs(){
return glyphs.length();
}
@Override
public Shape getOutline(){
throw new NotImplementedException();
}
@Override
public Shape getOutline(float x, float y){
throw new NotImplementedException();
}
@Override
public Rectangle2D getVisualBounds(){
throw new NotImplementedException();
}
@Override
public void performDefaultLayout(){
throw new NotImplementedException();
}
@Override
public void setGlyphPosition(int glyphIndex, Point2D newPos){
throw new NotImplementedException();
}
@Override
public void setGlyphTransform(int glyphIndex, AffineTransform newTX){
throw new NotImplementedException();
}
/**
* Convert a CharacterIterator to a string
* @param iterator the itereator
* @return the string
*/
private static String getString(java.text.CharacterIterator iterator){
iterator.first();
StringBuilder sb = new StringBuilder();
while(true){
char c = iterator.current();
if(c == CharacterIterator.DONE){
break;
}
sb.append(c);
iterator.next();
}
return sb.toString();
}
}