public void LoadSingleGlyphWithUInt8Offset_unsigned_byte() { var writer = new BigEndianBinaryWriter(); writer.WriteUInt16(0); // 8bit unsigned writer.WriteUInt16(1); // glyph id writer.WriteUInt8(sbyte.MaxValue + 1); // dx writer.WriteUInt8(sbyte.MaxValue + 2); // dy writer.GetReader(); var bounds = new Bounds(0, 0, 100, 100); var glyph = CompositeGlyphLoader.LoadCompositeGlyph(writer.GetReader(), in bounds); var tbl = new GlyphTable(new[] { new SimpleGlyphLoader(bounds), // padding new SimpleGlyphLoader(new short[] { 20 }, new short[] { 21 }, new[] { true }, new ushort[] { 1 }, bounds, Array.Empty <byte>()) }); GlyphVector finalGlyph = glyph.CreateGlyph(tbl); Vector2 point = Assert.Single(finalGlyph.GetOutline().ControlPoints.ToArray()); Assert.Equal(new Vector2(sbyte.MaxValue + 1 + 20, sbyte.MaxValue + 2 + 21), point); }
public void LoadSingleGlyphWithInt16Offset_signed_short() { var writer = new BigEndianBinaryWriter(); writer.WriteUInt16((ushort)(CompositeGlyphFlags.Args1And2AreWords /* 16bit */ | CompositeGlyphFlags.ArgsAreXYValues /* signed */)); // flags writer.WriteUInt16(1); // glyph id writer.WriteInt16(short.MinValue + 1); // dx writer.WriteInt16(short.MinValue + 2); // dy writer.GetReader(); var bounds = new Bounds(0, 0, 100, 100); var glyph = CompositeGlyphLoader.LoadCompositeGlyph(writer.GetReader(), in bounds); var tbl = new GlyphTable(new[] { new SimpleGlyphLoader(bounds), // padding new SimpleGlyphLoader(new short[] { 20 }, new short[] { 21 }, new[] { true }, new ushort[] { 1 }, bounds, Array.Empty <byte>()) }); GlyphVector finalGlyph = glyph.CreateGlyph(tbl); Vector2 point = Assert.Single(finalGlyph.GetOutline().ControlPoints.ToArray()); Assert.Equal(new Vector2(short.MinValue + 1 + 20, short.MinValue + 2 + 21), point); }
public void LoadSingleGlyphWithInt8Offset_signed_byte() { var writer = new BigEndianBinaryWriter(); writer.WriteUInt16((ushort)CompositeFlags.ArgsAreXYValues); // signed byte writer.WriteUInt16(1); // glyph id writer.WriteInt8(sbyte.MinValue + 1); // dx writer.WriteInt8(sbyte.MinValue + 2); // dy writer.GetReader(); var bounds = new Bounds(0, 0, 100, 100); var glyph = CompositeGlyphLoader.LoadCompositeGlyph(writer.GetReader(), in bounds); var tbl = new GlyphTable(new[] { new SimpleGlyphLoader(bounds), // padding new SimpleGlyphLoader(new short[] { 20 }, new short[] { 21 }, new[] { true }, new ushort[] { 1 }, bounds) }); GlyphVector finalGlyph = glyph.CreateGlyph(tbl); Vector2 point = Assert.Single(finalGlyph.ControlPoints); Assert.Equal(new Vector2(sbyte.MinValue + 1 + 20, sbyte.MinValue + 2 + 21), point); }
/// <summary> /// Gets the glyph. /// </summary> /// <param name="codePoint">The code point of the character.</param> /// <returns>the glyph for a known character.</returns> GlyphInstance IFontInstance.GetGlyph(int codePoint) { ushort idx = this.GetGlyphIndex(codePoint); if (this.glyphCache[idx] is null) { ushort advanceWidth = this.horizontalMetrics.GetAdvancedWidth(idx); short lsb = this.horizontalMetrics.GetLeftSideBearing(idx); GlyphVector vector = this.glyphs.GetGlyph(idx); this.glyphCache[idx] = new GlyphInstance(this, vector.ControlPoints, vector.OnCurves, vector.EndPoints, vector.Bounds, advanceWidth, lsb, this.EmSize, idx); } return(this.glyphCache[idx]); }
internal GlyphInstance(FontInstance font, GlyphVector vector, ushort advanceWidth, short leftSideBearing, ushort sizeOfEm, ushort index, GlyphType glyphType = GlyphType.Standard, GlyphColor?glyphColor = null) { this.Font = font; this.SizeOfEm = sizeOfEm; this.vector = vector; this.AdvanceWidth = advanceWidth; this.Index = index; this.Height = sizeOfEm - this.Bounds.Min.Y; this.GlyphType = glyphType; this.LeftSideBearing = leftSideBearing; this.ScaleFactor = this.SizeOfEm * 72F; this.GlyphColor = glyphColor; }
/// <summary> Returns the logical bounds of the given text. /// /// </summary> /// <param name="text">the text. /// </param> /// <returns> the logical bounds of the text. /// </returns> public virtual System.Drawing.RectangleF getTextLogicalBounds(System.String text) { #if PENDING //UPGRADE_TODO: Class 'java.awt.font.FontRenderContext' was converted to 'System.Windows.Forms.Control' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_3"' //UPGRADE_ISSUE: Constructor 'java.awt.font.FontRenderContext.FontRenderContext' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontFontRenderContextFontRenderContext_javaawtgeomAffineTransform_boolean_boolean_3"' System.Drawing.Text.TextRenderingHint frc = new FontRenderContext(new System.Drawing.Drawing2D.Matrix(), true, state.usesFractionalFontMetrics); //UPGRADE_ISSUE: Class 'java.awt.font.GlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"' //UPGRADE_TODO: Method 'java.awt.Font.createGlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1095_3"' GlyphVector gv = state.font.createGlyphVector(frc, text); //UPGRADE_ISSUE: Method 'java.awt.font.GlyphVector.getLogicalBounds' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"' return(gv.getLogicalBounds()); #endif return(new System.Drawing.RectangleF()); //TODO PENDING }
/// <summary> Draws the given text using the current font, Fill color and /// other settings. The positions of the characters are given /// as an array of floats. Each position is given as two /// numbers the x-position and y-position. /// /// </summary> /// <param name="text">the text to be drawn. /// </param> /// <param name="positions">the positions of the characters. /// </param> public virtual void drawText(System.String text, float[] positions) { #if PENDING //UPGRADE_TODO: Class 'java.awt.font.FontRenderContext' was converted to 'System.Windows.Forms.Control' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_3"' //UPGRADE_ISSUE: Constructor 'java.awt.font.FontRenderContext.FontRenderContext' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontFontRenderContextFontRenderContext_javaawtgeomAffineTransform_boolean_boolean_3"' System.Drawing.Text.TextRenderingHint frc = new FontRenderContext(new System.Drawing.Drawing2D.Matrix(), true, true); //UPGRADE_ISSUE: Class 'java.awt.font.GlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"' //UPGRADE_TODO: Method 'java.awt.Font.createGlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1095_3"' GlyphVector gv = state.font.createGlyphVector(frc, text); //UPGRADE_ISSUE: Method 'java.awt.font.GlyphVector.getGlyphCodes' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"' //UPGRADE_ISSUE: Method 'java.awt.font.GlyphVector.getNumGlyphs' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"' drawGlyphs(gv.getGlyphCodes(0, gv.getNumGlyphs(), null), positions); #endif }
public void TtfAppendGlyph_Works() { // arrange Vector2[] controlPoints = { new(1.0f), new(2.0f) }; Vector2[] expectedControlPoints = { new(1.0f), new(2.0f), new(1.0f), new(2.0f) }; bool[] onCurves = { true, false }; ushort[] endPoints = { 1, 2, 3 }; var bounds = new Bounds(1.0f, 2.0f, 3.0f, 4.0f); var glyphVector1 = new GlyphVector(controlPoints, onCurves, endPoints, bounds, Array.Empty <byte>()); var glyphVector2 = new GlyphVector(controlPoints, onCurves, endPoints, bounds, Array.Empty <byte>()); // act var appended = GlyphVector.Append(glyphVector1, glyphVector2, default); // assert Assert.True(expectedControlPoints.AsSpan().SequenceEqual(appended.GetOutline().ControlPoints.Span)); }
private GlyphInstance CreateInstance(ushort idx, GlyphType glyphType, ushort palleteIndex = 0) { ushort advanceWidth = this.horizontalMetrics.GetAdvancedWidth(idx); short lsb = this.horizontalMetrics.GetLeftSideBearing(idx); GlyphVector vector = this.glyphs.GetGlyph(idx); GlyphColor? color = null; if (glyphType == GlyphType.ColrLayer) { // 0xFFFF is special index meaning use foreground color and thus leave unset if (palleteIndex != 0xFFFF) { color = this.cpalTable?.GetGlyphColor(0, palleteIndex); } } return(new GlyphInstance(this, vector, advanceWidth, lsb, this.EmSize, idx, glyphType, color)); }
public void TtfOffsetXy_Works() { // arrange Vector2[] controlPoints = { new(1.0f), new(2.0f) }; bool[] onCurves = { true, false }; ushort[] endPoints = { 1, 2, 3 }; var bounds = new Bounds(1.0f, 2.0f, 3.0f, 4.0f); var expectedBounds = new Bounds(11.0f, 12.0f, 13.0f, 14.0f); var glyphVector = new GlyphVector(controlPoints, onCurves, endPoints, bounds, Array.Empty <byte>()); // act Matrix3x2 matrix = Matrix3x2.Identity; matrix.Translation = new Vector2(10, 10); var transformed = GlyphVector.Transform(glyphVector, matrix); // assert Assert.Equal(expectedBounds, transformed.GetBounds()); }
internal override System.Drawing.Rectangle getBounds(DrawContext context, System.Drawing.Drawing2D.Matrix transform) { #if PENDING System.Drawing.Rectangle r = System.Drawing.Rectangle.Empty; //UPGRADE_TODO: Class 'java.awt.font.FontRenderContext' was converted to 'System.Windows.Forms.Control' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_3"' //UPGRADE_ISSUE: Constructor 'java.awt.font.FontRenderContext.FontRenderContext' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontFontRenderContextFontRenderContext_javaawtgeomAffineTransform_boolean_boolean_3"' System.Drawing.Text.TextRenderingHint frc = new FontRenderContext(transform, false, true); for (int i = 0; i < glyphCodes.Length; i++) { //UPGRADE_ISSUE: Class 'java.awt.font.GlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtfontGlyphVector_3"' //UPGRADE_TODO: Method 'java.awt.Font.createGlyphVector' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1095_3"' GlyphVector gv = font.createGlyphVector(frc, new int[] { glyphCodes[i] }); System.Drawing.Rectangle gr = gv.getPixelBounds(frc, positions[i * 2], positions[i * 2 + 1]); if (r.IsEmpty) { r = gr; } else { r = System.Drawing.Rectangle.Union(r, gr); } } if (r.IsEmpty) { return(new System.Drawing.Rectangle()); } Filter filter = context.AAFilter; // Compensate for the antialiasing filter if (filter != null) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042_3"' //UPGRADE_NOTE: ref keyword was added to struct-type parameters. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1303_3"' r = addMargin(ref r, (int)System.Math.Ceiling(filter.Width), (int)System.Math.Ceiling(filter.Height)); } return(r); #endif return(new System.Drawing.Rectangle()); }
public void CloneIsDeep() { // arrange Vector2[] controlPoints = { new(1.0f), new(2.0f) }; bool[] onCurves = { true, false }; ushort[] endPoints = { 1, 2, 3 }; var bounds = new Bounds(1.0f, 2.0f, 3.0f, 4.0f); var glyphVector = new GlyphVector(controlPoints, onCurves, endPoints, bounds, Array.Empty <byte>()); GlyphOutline outline = glyphVector.GetOutline(); // act GlyphOutline clone = GlyphVector.DeepClone(glyphVector).GetOutline(); // assert Assert.False(outline.ControlPoints.Equals(clone.ControlPoints)); Assert.True(outline.ControlPoints.Span.SequenceEqual(clone.ControlPoints.Span)); Assert.False(outline.OnCurves.Equals(clone.OnCurves)); Assert.True(outline.OnCurves.Span.SequenceEqual(clone.OnCurves.Span)); Assert.False(outline.EndPoints.Equals(clone.EndPoints)); Assert.True(outline.EndPoints.Span.SequenceEqual(clone.EndPoints.Span)); }
/** * Renders the text of the specified * {@link GlyphVector} using * the <code>Graphics2D</code> context's rendering attributes. * The rendering attributes applied include the <code>Clip</code>, * <code>Transform</code>, <code>Paint</code>, and * <code>Composite</code> attributes. The <code>GlyphVector</code> * specifies individual glyphs from a {@link Font}. * The <code>GlyphVector</code> can also contain the glyph positions. * This is the fastest way to render a Set of characters to the * screen. * * @param g the <code>GlyphVector</code> to be rendered * @param x the x position in user space where the glyphs should be * rendered * @param y the y position in user space where the glyphs should be * rendered * * @see java.awt.Font#CreateGlyphVector(FontRenderContext, char[]) * @see java.awt.font.GlyphVector * @see #setPaint * @see java.awt.Graphics#setColor * @see #setTransform * @see #setComposite * @see #setClip(Shape) */ public void DrawGlyphVector(GlyphVector g, float x, float y) { Shape glyphOutline = g.GetOutline(x, y); Fill(glyphOutline); }
public void DrawGlyphVector(GlyphVector g, float x, float y) { Fill(g.GetOutline(x, y)); }
public FakeGlyphSource(int codePoint, ushort index, GlyphVector vector) { this.CodePoint = codePoint; this.Vector = vector; this.Index = index; }
internal GlyphVectorWithColor(GlyphVector vector, GlyphColor color) { this.Vector = vector; this.Color = color; }
public TransformedGlyphLoader(GlyphVector glyphVector) => this.glyphVector = glyphVector;
/** * @see Graphics2D#drawGlyphVector(GlyphVector, float, float) */ public void drawGlyphVector(GlyphVector g, float x, float y) { Shape s = g.getOutline(x, y); fill(s); }
/// <summary> /// Renders the text of the specified /// <A HREF="../../java/awt/font/GlyphVector.html" title="class in java.awt.font"><CODE>GlyphVector</CODE></A> using /// the <code>Graphics2D</code> context's rendering attributes. /// </summary> abstract public void drawGlyphVector(GlyphVector @g, float @x, float @y);
public FakeGlyphSource(char character, ushort index, GlyphVector vector) { this.Character = character; this.Vector = vector; this.Index = index; }