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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
using System;
using System.Drawing;
using Emgu.CV;
using Emgu.CV.CvEnum;
namespace UVtools.Core.PixelEditor
{
public class PixelText : PixelOperation
{
private FontFace _font;
private double _fontScale = 1;
private ushort _thickness = 1;
private string _text;
private bool _mirror;
private double _angle;
private byte _removePixelBrightness;
public override PixelOperationType OperationType => PixelOperationType.Text;
public static FontFace[] FontFaces => (FontFace[]) Enum.GetValues(typeof(FontFace));
public FontFace Font
{
get => _font;
set => RaiseAndSetIfChanged(ref _font, value);
}
public double FontScale
{
get => _fontScale;
set => RaiseAndSetIfChanged(ref _fontScale, Math.Round(value, 2));
}
public ushort Thickness
{
get => _thickness;
set => RaiseAndSetIfChanged(ref _thickness, value);
}
public string Text
{
get => _text;
set => RaiseAndSetIfChanged(ref _text, value);
}
public bool Mirror
{
get => _mirror;
set => RaiseAndSetIfChanged(ref _mirror, value);
}
public double Angle
{
get => _angle;
set => RaiseAndSetIfChanged(ref _angle, value);
}
public byte RemovePixelBrightness
{
get => _removePixelBrightness;
set
{
if (!RaiseAndSetIfChanged(ref _removePixelBrightness, value)) return;
RaisePropertyChanged(nameof(RemovePixelBrightnessPercent));
}
}
public decimal RemovePixelBrightnessPercent => Math.Round(_removePixelBrightness * 100M / 255M, 2);
public bool IsAdd { get; }
public byte Brightness => IsAdd ? _pixelBrightness : _removePixelBrightness;
public Rectangle Rectangle { get; }
public PixelText(){}
public PixelText(uint layerIndex, Point location, LineType lineType, FontFace font, double fontScale, ushort thickness, string text, bool mirror, double angle, byte removePixelBrightness, byte pixelBrightness, bool isAdd) : base(layerIndex, location, lineType, pixelBrightness)
{
_font = font;
_fontScale = fontScale;
_thickness = thickness;
_text = text;
_mirror = mirror;
_angle = angle;
IsAdd = isAdd;
_removePixelBrightness = removePixelBrightness;
int baseLine = 0;
Size = CvInvoke.GetTextSize(text, font, fontScale, thickness, ref baseLine);
Rectangle = new Rectangle(location, Size);
}
}
}
|