-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProgram.cs
77 lines (57 loc) · 2.5 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
namespace example;
// example-0012
// show text alignment types with their bounding box
class Program
{
static void Main(string[] args)
{
InitAvalonia();
var w = GLWindow.Create();
w.GLModel.BuildModel = (glCtl, isInitial) =>
{
if (!isInitial) return;
var glModel = glCtl.GLModel;
glModel.Clear();
glModel.AddFigure(MakeWCSFigure());
var useCustomFont = true;
float textHeight;
SKFont? customFont = null;
if (useCustomFont)
{
customFont = SKFontManager.Default.MatchFamily("Manjari Thin").ToFont();
textHeight = 1f;
}
else
{
textHeight = .8f;
}
void addText(Vector3 insPt, string text, GLTextVHAlignment alignment)
{
// show insertion point with a point ( 10 pixel [screen] )
glModel.AddFigure(new GLPointFigure(new GLPoint(new GLVertex(insPt, Color.Cyan))) { PointSize = 10 });
var fig = glModel.MakeTextFigure(new GLText(WCS.Move(insPt), text)
{
Height = textHeight,
Alignment = alignment
}.Act(txt => { if (customFont is not null) txt.Font = customFont; }));
glModel.AddFigure(fig);
// show text bbox with a yellow rectangle
var figBBox = new BBox(fig.Select(w => w.OBBox))
.MakeFigure(Color.Yellow);
glModel.AddFigure(figBBox);
}
addText(new Vector3(0, 4, 0), "TopLeft", GLTextVHAlignment.TopLeft);
addText(new Vector3(0, 2, 0), "MiddleLeft", GLTextVHAlignment.MiddleLeft);
addText(new Vector3(0, 0, 0), "BottomLeft", GLTextVHAlignment.BottomLeft);
addText(new Vector3(10, 4, 0), "TopCenter", GLTextVHAlignment.TopCenter);
addText(new Vector3(10, 2, 0), "MiddleCenter", GLTextVHAlignment.MiddleCenter);
addText(new Vector3(10, 0, 0), "BottomCenter", GLTextVHAlignment.BottomCenter);
addText(new Vector3(20, 4, 0), "TopRight", GLTextVHAlignment.TopRight);
addText(new Vector3(20, 2, 0), "MiddleRight", GLTextVHAlignment.MiddleRight);
addText(new Vector3(20, 0, 0), "BottomRight", GLTextVHAlignment.BottomRight);
glCtl.Perspective = false;
glCtl.CameraView(CameraViewType.Top);
};
w.ShowSync();
}
}