Replies: 3 comments 6 replies
-
@woutware I've converted this to a discussion since it's not an issue. I'm honestly a little surprised and disappointed that you chose to delete the issue template. First things first. This is beta software. We don't have a stable API and we explicitly call that out in the documentation.
We wouldn't and couldn't add Now to answer your question.
Every single change has been discussed and made in the public domain with the relevant PRs linked in the release notes. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the quick reply and clarifying the changes. I wanted to submit an issue rather than create a discussion as it was an issue for me. My issue just didn't fit the template, that's all. Anyways, I would argue that especially in Beta the [Obsolete] tag is useful, since that's when API changes will happen mostly. Doesn't that make sense? For each of the changes above I would have taken minutes in making all the adjustments rather than checking out diffs on github for half a day. I don't see much point in adopting the [Obsolete] tag when the API has settled down, what's the rationale of not using it in beta? Also this package has been in beta for years, without any date on a release date. |
Beta Was this translation helpful? Give feedback.
-
I actually wanted to ask a question. I'm interested in acquiring glyph's data (shapes). Previously (version 0.0...don't remember) I was doing it like this: using F = SixLabors.Fonts;
using X = com.audionysos.text.render;
namespace WpfDNet {
public class SLGlyphsProvider : GlyphsProvider {
public override X.Glyph get(char ch, ITextFormat f) {
if (ch == ' ') return missingGlyph;
var ff = F.SystemFonts.Find(f.font.name);
var font = ff.CreateFont((float)f.size);
var gl = font.GetGlyph(ch);
var gi = gl.Instance;
//gi.
var min = gi.Height - font.EmSize;
var scale = (float)f.size / 11; var x = 0; var y = 0;
var sf = (font.Ascender + font.Descender) / gi.ScaleFactor * scale;
//var sf = (font.Ascender) / gi.ScaleFactor * scale;
var s = new System.Numerics.Vector2(sf, -sf);
var off = new System.Numerics.Vector2(0 + x, (gi.Height - min) * s.X + y);
var cp = gi.ControlPoints[0] * s + off;
var fp = cp;
var color = 0u;
var width = 0; var height = 0;
var phs = new List<X.Path>();
var ph = new X.Path();
phs.Add(ph);
ph.Add(cp.X, cp.Y);
var nep = gi.EndPoints[0]; var epi = 0;
var m = false;
for (int i = 1; i < gi.ControlPoints.Length; i++) {
cp = gi.ControlPoints[i] * s + off;
if (m) {
ph = new X.Path();
phs.Add(ph);
ph.Add(cp.X, cp.Y);
m = false;
fp = cp;
continue;
}
ph.Add(cp.X, cp.Y);
if (nep == i) {
//g.lineTo(fp.X, fp.Y);
epi++;
if (epi < gi.EndPoints.Length)
nep = gi.EndPoints[epi];
m = true;
}
}
var r = new X.Glyph(width, height, phs);
return r;
}
}
} Now I can't find the using F = SixLabors.Fonts;
using SixLabors.Fonts;
using System.Numerics;
using X = com.audionysos.text.render;
using System.Collections.Generic;
using System;
namespace WpfDNet {
public class bla : F.IGlyphRenderer {
public List<X.Path> phs = new ();
private X.Path ph = null;
private Vector2 cp;
public TextDecorations EnabledDecorations() {
return TextDecorations.None;
}
public void SetDecoration(TextDecorations textDecorations, Vector2 start, Vector2 end, float thickness)
{}
public void BeginText(in FontRectangle bounds) {}
public bool BeginGlyph(in FontRectangle bounds, in GlyphRendererParameters parameters)
=> true;
public void BeginFigure() {
//ph = new X.Path ();
cp = new Vector2();
}
private float s = 1;
public void LineTo(Vector2 p) {
cp = p * s;
ph.Add(cp.X, cp.Y);
}
public void MoveTo(Vector2 point) {
if(ph != null) phs.Add(ph);
ph = new X.Path();
cp = point * s;
ph.Add(cp.X, cp.Y);
}
public void QuadraticBezierTo(Vector2 c, Vector2 e) {
var g = 10f;
for (int i = 1; i <= g; i++) {
var t = i / g;
var m1 = mid(cp, c, t);
var m2 = mid(c, e, t);
cp = mid(m1, m2, t);
cp *= s;
ph.Add(cp.X, cp.Y);
}
}
private Vector2 mid(Vector2 s, Vector2 e, float t)
=> s + (e - s) * t;
public void CubicBezierTo(Vector2 c, Vector2 c2, Vector2 e) {
var g = 10f;
for (int i = 0; i <= g; i++) {
var t = i / g;
var m1 = mid(cp, c, t);
var m2 = mid(c, c2, t);
var m3 = mid(c2, e, t);
var m21 = mid(m1 , m2, t);
var m22 = mid(m2 , m3, t);
cp = mid(m21, m22, t);
cp *= s;
ph.Add(cp.X, cp.Y);
}
}
public void EndFigure() {
//var sp = ph[0];
//ph.Add(sp);
phs.Add(ph);
}
public void EndGlyph() {}
public void EndText() {}
}
}
using com.audionysos.text.edit;
using com.audionysos.text.render;
using SixLabors.Fonts;
using System.Collections.Generic;
using F = SixLabors.Fonts;
using X = com.audionysos.text.render;
namespace WpfDNet {
public class SLGlyphsProvider : GlyphsProvider {
public override X.Glyph get(char ch, ITextFormat f) {
if (ch == ' ') return missingGlyph;
var font = F.SystemFonts.CreateFont(f.font.name, (float)f.size);
font.TryGetGlyphs(new F.Unicode.CodePoint(ch), out var glyphs);
var g = glyphs[0];
var b = new bla();
TextRenderer.RenderTextTo(b, ch.ToString(), new TextOptions(font) {
});
var rc = g.BoundingBox(GlyphLayoutMode.Horizontal
,new System.Numerics.Vector2(), 128);
var width = rc.Width; var height = 0;
var r = new X.Glyph(width, height, b.phs);
return r;
}
}
} So now output of my glyph provider shouldn't be different. However I have problem with the holes: I have no idea what is happening. I don't know If I implemented the #region Image sharp rendering
/// <summary>ImageSharp ready figures</summary>
private List<SharpFigure> sFigures = new List<SharpFigure>();
private void covertToSharpFigures() {
sFigures.Clear();
var joined = new List<Figure>(); //figures with the same brush are joined so the ImageSharp will create holes (rendering glyphs)
Figure last = null;
for (int i = 0; i < tFigures.Count; i++) {
var tf = tFigures[i];
if (last == null || tf.sameStyle(last)) {
joined.Add(tf);
last = tf;
continue;
}
var sf = new SharpFigure(joined, last.fill, last.stroke);
sFigures.Add(sf);
joined.Clear(); last = null;
}
if (joined.Count == 0) return;
sFigures.Add(new SharpFigure(joined, last.fill, last.stroke));
}
public void render(Image<Bgra32> img) {
img.Mutate(x => {
for (int i = 0; i < sFigures.Count; i++) {
var f = sFigures[i];
if (f.brush != null)
x.Fill(f.brush, f.path);
if (f.pen == null) continue;
for (int j = 0; j < f.points.Length; j++) {
//x.DrawLines(f.pen, f.points[j]);
x.DrawLine(f.pen, f.points[j]);
}
}
});
}
#endregion In case you would want to look, you can find above code here: I don't expect you to dig in my code or solve my issues but I don't know were to go from here. This is my spare time project I didn't touched for two years or so and now when I finally got inspired to push it forward I've already spend two days trying to make it work as it was already... :| I understand this was beta version but I hope you would understand me too and maybe give me some pointers. |
Beta Was this translation helpful? Give feedback.
-
Class RendererOptions missing, what's the replacement? I guess TextOptions?
Constructor new TextOptions(Font, Vector2) missing (was there for RendererOptions).
Property Font.EmSize is missing, can't find them in Font.FontMetrics.
Class IReadonlyFontCollectionExtensions is entirely missing. I used to call IReadonlyFontCollectionExtensions.CreateFont to create a font. What replaced this? I'm guessing just call new Font(...).
Class GlyphMetric is missing, I'm guessing GlyphBounds.
You can make it easier on users by leaving the classes/methods/properties where they are and marking them [Obsolete] with a description of what the user is to be using instead. And then leave it there for 5 years or so to give us plenty of time to migrate. Not everyone is updating their dependencies multiple times a year.
Beta Was this translation helpful? Give feedback.
All reactions