Imported Upstream version 3.10.0

Former-commit-id: 172c8e3c300b39d5785c7a3e8dfb08ebdbc1a99b
This commit is contained in:
Jo Shields
2014-10-04 11:27:48 +01:00
parent fe777c5c82
commit 8b9b85e7f5
970 changed files with 20242 additions and 31308 deletions

View File

@@ -1,7 +1,7 @@
/*
Copyright (C) 2002, 2004, 2005, 2006, 2007 Jeroen Frijters
Copyright (C) 2006 Active Endpoints, Inc.
Copyright (C) 2006 - 2013 Volker Berlin (i-net software)
Copyright (C) 2006 - 2014 Volker Berlin (i-net software)
Copyright (C) 2011 Karsten Heinrich (i-net software)
This software is provided 'as-is', without any express or implied
@@ -40,17 +40,29 @@ namespace ikvm.awt
internal class BitmapGraphics : NetGraphics
{
private readonly Bitmap bitmap;
private readonly BufferedImage image;
internal BitmapGraphics(Bitmap bitmap, java.awt.Font font, Color fgcolor, Color bgcolor)
: base(createGraphics(bitmap), font, fgcolor, bgcolor)
internal BitmapGraphics(Bitmap bitmap, Object destination, java.awt.Font font, Color fgcolor, Color bgcolor)
: base(createGraphics(bitmap), destination, font, fgcolor, bgcolor)
{
this.bitmap = bitmap;
image = destination as BufferedImage;
}
internal BitmapGraphics(Bitmap bitmap)
: base(createGraphics(bitmap), null, Color.White, Color.Black)
internal BitmapGraphics(Bitmap bitmap, Object destination)
: this(bitmap, destination, null, Color.White, Color.Black)
{
this.bitmap = bitmap;
}
internal override Graphics g
{
get {
if (image != null)
{
image.toBitmap();
}
return base.g;
}
}
protected override SizeF GetSize() {
@@ -89,8 +101,8 @@ namespace ikvm.awt
{
private readonly Control control;
internal ComponentGraphics(Control control, java.awt.Color fgColor, java.awt.Color bgColor, java.awt.Font font)
: base(control.CreateGraphics(), font, J2C.ConvertColor(fgColor), J2C.ConvertColor(bgColor))
internal ComponentGraphics(Control control, java.awt.Component target, java.awt.Color fgColor, java.awt.Color bgColor, java.awt.Font font)
: base(control.CreateGraphics(), target, font, J2C.ConvertColor(fgColor), J2C.ConvertColor(bgColor))
{
this.control = control;
}
@@ -116,12 +128,17 @@ namespace ikvm.awt
return (Point)this.control.Invoke(new Converter<Point,Point>(getPointToScreenImpl),point);
}
public override void copyArea(int x, int y, int width, int height, int dx, int dy)
{
Point src = getPointToScreen(new Point(x + (int)this.g.Transform.OffsetX, y + (int)this.g.Transform.OffsetY));
Point dest = new Point(x + (int)this.g.Transform.OffsetX + dx, y + (int)this.g.Transform.OffsetY + dy);
this.g.CopyFromScreen(src, dest, new Size(width, height));
}
public override void copyArea(int x, int y, int width, int height, int dx, int dy)
{
Matrix t = g.Transform;
Point src = getPointToScreen(new Point(x + (int)t.OffsetX, y + (int)t.OffsetY));
Bitmap copy = new Bitmap(width, height);
using (Graphics gCopy = Graphics.FromImage(copy))
{
gCopy.CopyFromScreen(src, new Point(0, 0), new Size(width, height));
}
g.DrawImageUnscaled(copy, x + dx, y + dy);
}
public override void clip(java.awt.Shape shape)
{
@@ -150,7 +167,7 @@ namespace ikvm.awt
private bool isBase = true;
internal PrintGraphics(Graphics g)
: base(g, null, Color.White, Color.Black)
: base(g, null, null, Color.White, Color.Black)
{
baseContext = new PrintGraphicsContext();
baseContext.Current = this;
@@ -744,7 +761,7 @@ namespace ikvm.awt
netG.g.Clip = Clip;
netG.g.SmoothingMode = SmoothingMode;
netG.g.PixelOffsetMode = PixelOffsetMode;
netG.g.TextRenderingHint = TextRenderingHint;
netG.setTextRenderingHint(TextRenderingHint);
netG.g.InterpolationMode = InterpolationMode;
netG.g.CompositingMode = CompositingMode;
}
@@ -768,10 +785,9 @@ namespace ikvm.awt
}
}
internal abstract class NetGraphics : java.awt.Graphics2D
internal abstract class NetGraphics : java.awt.Graphics2D//sun.java2d.SunGraphics2D
{
internal Graphics g;
internal Graphics JGraphics { get { return g; } }
private Graphics graphics;
private java.awt.Color javaColor;
private java.awt.Paint javaPaint;
internal Color color;
@@ -780,6 +796,7 @@ namespace ikvm.awt
private java.awt.Stroke stroke;
private static java.awt.BasicStroke defaultStroke = new java.awt.BasicStroke();
private Font netfont;
private int baseline;
internal Brush brush;
internal Pen pen;
private CompositeHelper composite;
@@ -787,7 +804,16 @@ namespace ikvm.awt
private Object textAntialiasHint;
private Object fractionalHint = java.awt.RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT;
protected NetGraphics(Graphics g, java.awt.Font font, Color fgcolor, Color bgcolor)
private static System.Collections.Generic.Dictionary<String, Int32> baselines = new System.Collections.Generic.Dictionary<String, Int32>();
internal static readonly StringFormat FORMAT = new StringFormat(StringFormat.GenericTypographic);
static NetGraphics()
{
FORMAT.FormatFlags = StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox;
FORMAT.Trimming = StringTrimming.None;
}
protected NetGraphics(Graphics g, Object destination, java.awt.Font font, Color fgcolor, Color bgcolor) //: base( new sun.java2d.SurfaceData(destination) )
{
if (font == null)
{
@@ -801,12 +827,21 @@ namespace ikvm.awt
init(g);
}
/// <summary>
/// The current C# Graphics
/// </summary>
internal virtual Graphics g
{
get { return graphics; }
set { graphics = value; }
}
protected void init(Graphics graphics)
{
NetGraphicsState state = new NetGraphicsState();
state.saveGraphics(this);
g = graphics;
state.restoreGraphics(this);
state.restoreGraphics(this);
}
/// <summary>
@@ -850,7 +885,7 @@ namespace ikvm.awt
{
if (pen!=null) pen.Dispose();
if (brush!=null) brush.Dispose();
g.Dispose();
graphics.Dispose(); //for dispose we does not need to synchronize the buffer of a bitmap
}
public override void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
@@ -1190,6 +1225,7 @@ namespace ikvm.awt
{
netfont = f.getNetFont();
font = f;
baseline = getBaseline( netfont, g.TextRenderingHint );
}
}
@@ -1278,30 +1314,33 @@ namespace ikvm.awt
drawString(str, (float)x, (float)y);
}
public override void drawString(String text, float x, float y)
{
if (text.Length == 0)
{
public override void drawString(String text, float x, float y) {
if (text.Length == 0) {
return;
}
bool fractional = isFractionalMetrics();
StringFormat format = new StringFormat(StringFormat.GenericTypographic);
format.FormatFlags = StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox;
format.Trimming = StringTrimming.None;
if (fractional || !sun.font.StandardGlyphVector.isSimpleString(font, text))
{
g.DrawString(text, netfont, brush, x, y - font.getSize(), format);
}
else
{
// fixed metric for simple text, we position every character to simulate the Java behaviour
java.awt.font.FontRenderContext frc = new java.awt.font.FontRenderContext(null, isAntiAlias(), fractional);
sun.font.FontDesignMetrics metrics = sun.font.FontDesignMetrics.getMetrics(font, frc);
y -= font.getSize();
for (int i = 0; i < text.Length; i++)
{
g.DrawString(text.Substring(i, 1), netfont, brush, x, y, format);
x += metrics.charWidth(text[i]);
CompositingMode origCM = g.CompositingMode;
try {
if (origCM != CompositingMode.SourceOver) {
// Java has a different behaviar for AlphaComposite and Text Antialiasing
g.CompositingMode = CompositingMode.SourceOver;
}
bool fractional = isFractionalMetrics();
if (fractional || !sun.font.StandardGlyphVector.isSimpleString(font, text)) {
g.DrawString(text, netfont, brush, x, y - baseline, FORMAT);
} else {
// fixed metric for simple text, we position every character to simulate the Java behaviour
java.awt.font.FontRenderContext frc = new java.awt.font.FontRenderContext(null, isAntiAlias(), fractional);
sun.font.FontDesignMetrics metrics = sun.font.FontDesignMetrics.getMetrics(font, frc);
y -= baseline;
for (int i = 0; i < text.Length; i++) {
g.DrawString(text.Substring(i, 1), netfont, brush, x, y, FORMAT);
x += metrics.charWidth(text[i]);
}
}
} finally {
if (origCM != CompositingMode.SourceOver) {
g.CompositingMode = origCM;
}
}
}
@@ -1345,6 +1384,9 @@ namespace ikvm.awt
public override void setComposite(java.awt.Composite comp)
{
if (javaComposite == comp) {
return;
}
if (comp == null)
{
throw new java.lang.IllegalArgumentException("null Composite");
@@ -1750,13 +1792,13 @@ namespace ikvm.awt
if (hintValue == java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT ||
hintValue == java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
{
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
setTextRenderingHint(TextRenderingHint.SingleBitPerPixelGridFit);
textAntialiasHint = hintValue;
return;
}
if (hintValue == java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON)
{
g.TextRenderingHint = TextRenderingHint.AntiAlias;
setTextRenderingHint(TextRenderingHint.AntiAlias);
textAntialiasHint = hintValue;
return;
}
@@ -1933,6 +1975,71 @@ namespace ikvm.awt
return stroke;
}
internal void setTextRenderingHint(TextRenderingHint hint)
{
g.TextRenderingHint = hint;
baseline = getBaseline(netfont, hint);
}
/// <summary>
/// Caclulate the baseline from a font and a TextRenderingHint
/// </summary>
/// <param name="font">the font</param>
/// <param name="hint">the used TextRenderingHint</param>
/// <returns></returns>
private static int getBaseline(Font font, TextRenderingHint hint)
{
lock (baselines)
{
String key = font.ToString() + hint.ToString();
int baseline;
if (!baselines.TryGetValue(key, out baseline))
{
FontFamily family = font.FontFamily;
FontStyle style = font.Style;
float ascent = family.GetCellAscent(style);
float lineSpace = family.GetLineSpacing(style);
baseline = (int)Math.Round(font.GetHeight() * ascent / lineSpace);
// Until this point the calulation use only the Font. But with different TextRenderingHint there are smal differences.
// There is no API that calulate the offset from TextRenderingHint that we messure it.
const int w = 3;
const int h = 3;
Bitmap bitmap = new Bitmap(w, h);
Graphics g = Graphics.FromImage(bitmap);
g.TextRenderingHint = hint;
g.FillRectangle(new SolidBrush(Color.White), 0, 0, w, h);
g.DrawString("A", font, new SolidBrush(Color.Black), 0, -baseline, FORMAT);
g.DrawString("X", font, new SolidBrush(Color.Black), 0, -baseline, FORMAT);
g.Dispose();
int y = 0;
LINE:
while (y < h)
{
for (int x = 0; x < w; x++)
{
Color color = bitmap.GetPixel(x, y);
if (color.GetBrightness() < 0.5)
{
//there is a black pixel, we continue in the next line.
baseline++;
y++;
goto LINE;
}
}
break; // there was a line without black pixel
}
baselines[key] = baseline;
}
return baseline;
}
}
private bool isAntiAlias()
{
switch (g.TextRenderingHint)
@@ -1962,6 +2069,7 @@ namespace ikvm.awt
Matrix currentMatrix = null;
Font currentFont = netfont;
TextRenderingHint currentHint = g.TextRenderingHint;
int currentBaseline = baseline;
try
{
java.awt.Font javaFont = gv.getFont();
@@ -1969,19 +2077,22 @@ namespace ikvm.awt
{
netfont = javaFont.getNetFont();
}
TextRenderingHint hint;
if (frc.isAntiAliased()) {
if( frc.usesFractionalMetrics() ){
g.TextRenderingHint = TextRenderingHint.AntiAlias;
hint = TextRenderingHint.AntiAlias;
} else {
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
hint = TextRenderingHint.AntiAliasGridFit;
}
} else {
if (frc.usesFractionalMetrics()) {
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
hint = TextRenderingHint.SingleBitPerPixel;
} else {
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
hint = TextRenderingHint.SingleBitPerPixelGridFit;
}
}
g.TextRenderingHint = hint;
baseline = getBaseline(netfont, hint);
if (!frc.getTransform().equals(getTransform()))
{
// save the old context and use the transformation from the renderContext
@@ -1994,6 +2105,7 @@ namespace ikvm.awt
{
// Restore the old context if needed
g.TextRenderingHint = currentHint;
baseline = currentBaseline;
netfont = currentFont;
if (currentMatrix != null)
{
@@ -2144,14 +2256,20 @@ namespace ikvm.awt
}
}
public class NetGraphicsEnvironment : java.awt.GraphicsEnvironment
public class NetGraphicsEnvironment : sun.java2d.SunGraphicsEnvironment
{
public override bool isDisplayLocal()
{
return true;
}
// Create a bitmap with the dimensions of the argument image. Then
// create a graphics objects from the bitmap. All paint operations will
// then paint the bitmap.
public override java.awt.Graphics2D createGraphics(BufferedImage bi)
{
return new BitmapGraphics(bi.getBitmap());
return new BitmapGraphics(bi.getBitmap(), bi );
}
public override java.awt.Font[] getAllFonts()

View File

@@ -1 +1 @@
4341b9c30b528a9c448533ed715fc437369b3561
474cfafc92a8fad74e36e71fb612ebd44209bce8