Skip to content

Commit 6eaf95e

Browse files
Alignment with last SVGIconImageList and Image32 library, SynPDF and Markdown processor
1 parent ba21ce3 commit 6eaf95e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3044
-13365
lines changed

Ext/SVGIconImageList/Image32/source/Img32.CQ.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
(*******************************************************************************
44
* Author : Angus Johnson *
5-
* Version : 4.0 *
6-
* Date : 22 December 2021 *
5+
* Version : 4.2 *
6+
* Date : 30 May 2022 *
77
* Website : http://www.angusj.com *
88
* Copyright : Angus Johnson 2019-2021 *
99
* Purpose : Color reduction for TImage32 *

Ext/SVGIconImageList/Image32/source/Img32.Clipper.pas renamed to Ext/SVGIconImageList/Image32/source/Img32.Clipper2.pas

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
unit Img32.Clipper;
1+
unit Img32.Clipper2;
22

33
(*******************************************************************************
44
* Author : Angus Johnson *
5-
* Version : 2.24 *
6-
* Date : 26 June 2021 *
5+
* Version : 4.2 *
6+
* Date : 30 May 2022 *
77
* Website : http://www.angusj.com *
8-
* Copyright : Angus Johnson 2019-2021 *
8+
* Copyright : Angus Johnson 2019-2022 *
99
* Purpose : Wrapper module for the Clipper library *
1010
* License : http://www.boost.org/LICENSE_1_0.txt *
1111
*******************************************************************************)
1212

1313
interface
1414

1515
uses
16-
ClipperCore, Clipper, ClipperOffset,
1716
Img32, Img32.Draw, Img32.Vector;
1817

1918
//nb: InflatePath assumes that there's consistent winding where
@@ -48,14 +47,16 @@ function DifferencePolygons(const polygons1, polygons2: TPathsD;
4847

4948
implementation
5049

50+
uses Clipper, Clipper.Core, Clipper.Engine, Clipper.Offset;
51+
5152
//------------------------------------------------------------------------------
5253
//------------------------------------------------------------------------------
5354

54-
function InflatePath(const path: TPathD;
55+
function InflatePath(const path: Img32.TPathD;
5556
delta: Double; joinStyle: TJoinStyle; endStyle: TEndStyle;
56-
miterLimit: double; arcTolerance: double; minEdgeLength: double): TPathsD;
57+
miterLimit: double; arcTolerance: double; minEdgeLength: double): Img32.TPathsD;
5758
var
58-
paths: TPathsD;
59+
paths: Img32.TPathsD;
5960
begin
6061
setLength(paths, 1);
6162
paths[0] := path;
@@ -64,11 +65,11 @@ function InflatePath(const path: TPathD;
6465
end;
6566
//------------------------------------------------------------------------------
6667

67-
function InflatePaths(const paths: TPathsD;
68+
function InflatePaths(const paths: Img32.TPathsD;
6869
delta: Double; joinStyle: TJoinStyle; endStyle: TEndStyle;
69-
miterLimit: double; arcTolerance: double; minEdgeLength: double): TPathsD;
70+
miterLimit: double; arcTolerance: double; minEdgeLength: double): Img32.TPathsD;
7071
var
71-
jt: ClipperOffset.TJoinType;
72+
jt: Clipper.Offset.TJoinType;
7273
et: TEndType;
7374
begin
7475
case joinStyle of
@@ -84,93 +85,93 @@ function InflatePaths(const paths: TPathsD;
8485
esRound: et := etRound;
8586
else et := etPolygon;
8687
end;
87-
Result := TPathsD(ClipperOffset.InflatePaths(
88-
ClipperCore.TPathsD(paths), delta,
89-
jt, et, miterLimit, arcTolerance, minEdgeLength));
88+
Result := Img32.TPathsD(Clipper.InflatePaths(
89+
Clipper.Core.TPathsD(paths), delta, jt, et));
9090
end;
9191
//------------------------------------------------------------------------------
9292

93-
function UnionPolygon(const polygon: TPathD; fillRule: TFillRule): TPathsD;
93+
function UnionPolygon(const polygon: Img32.TPathD;
94+
fillRule: Img32.Vector.TFillRule): Img32.TPathsD;
9495
begin
9596
with TClipperD.Create do
9697
try
97-
AddPath(ClipperCore.TPathD(polygon));
98+
AddSubject(Clipper.Core.TPathD(polygon));
9899
Execute(ctUnion,
99-
ClipperCore.TFillRule(fillRule), ClipperCore.TPathsD(result));
100+
Clipper.Core.TFillRule(fillRule), Clipper.Core.TPathsD(result));
100101
finally
101102
Free;
102103
end;
103104
end;
104105
//------------------------------------------------------------------------------
105106

106-
function UnionPolygons(const polygons: TPathsD;
107-
fillRule: TFillRule): TPathsD;
107+
function UnionPolygons(const polygons: Img32.TPathsD;
108+
fillRule: Img32.Vector.TFillRule): Img32.TPathsD;
108109
begin
109110
with TClipperD.Create do
110111
try
111-
AddPaths(ClipperCore.TPathsD(polygons));
112+
AddSubject(Clipper.Core.TPathsD(polygons));
112113
Execute(ctUnion,
113-
ClipperCore.TFillRule(fillRule), ClipperCore.TPathsD(result));
114+
Clipper.Core.TFillRule(fillRule), Clipper.Core.TPathsD(result));
114115
finally
115116
Free;
116117
end;
117118
end;
118119
//------------------------------------------------------------------------------
119120

120-
function UnionPolygons(const polygon1, polygon2: TPathD;
121-
fillRule: TFillRule): TPathsD;
121+
function UnionPolygons(const polygon1, polygon2: Img32.TPathD;
122+
fillRule: Img32.Vector.TFillRule): Img32.TPathsD;
122123
begin
123124
with TClipperD.Create do
124125
try
125-
AddPath(ClipperCore.TPathD(polygon1), ptSubject);
126-
AddPath(ClipperCore.TPathD(polygon2), ptClip);
126+
AddSubject(Clipper.Core.TPathD(polygon1));
127+
AddClip(Clipper.Core.TPathD(polygon2));
127128
Execute(ctUnion,
128-
ClipperCore.TFillRule(fillRule), ClipperCore.TPathsD(result));
129+
Clipper.Core.TFillRule(fillRule), Clipper.Core.TPathsD(result));
129130
finally
130131
Free;
131132
end;
132133
end;
133134
//------------------------------------------------------------------------------
134135

135-
function UnionPolygons(const polygons1, polygons2: TPathsD;
136-
fillRule: TFillRule): TPathsD;
136+
function UnionPolygons(const polygons1, polygons2: Img32.TPathsD;
137+
fillRule: Img32.Vector.TFillRule): Img32.TPathsD;
137138
begin
138139
with TClipperD.Create do
139140
try
140-
AddPaths(ClipperCore.TPathsD(polygons1), ptSubject);
141-
AddPaths(ClipperCore.TPathsD(polygons2), ptClip);
141+
AddSubject(Clipper.Core.TPathsD(polygons1));
142+
AddClip(Clipper.Core.TPathsD(polygons2));
142143
Execute(ctUnion,
143-
ClipperCore.TFillRule(fillRule), ClipperCore.TPathsD(result));
144+
Clipper.Core.TFillRule(fillRule), Clipper.Core.TPathsD(result));
144145
finally
145146
Free;
146147
end;
147148
end;
148149
//------------------------------------------------------------------------------
149150

150-
function IntersectPolygons(const polygons1, polygons2: TPathsD;
151-
fillRule: TFillRule): TPathsD;
151+
function IntersectPolygons(const polygons1, polygons2: Img32.TPathsD;
152+
fillRule: Img32.Vector.TFillRule): Img32.TPathsD;
152153
begin
153154
with TClipperD.Create do
154155
try
155-
AddPaths(ClipperCore.TPathsD(polygons1), ptSubject);
156-
AddPaths(ClipperCore.TPathsD(polygons2), ptClip);
156+
AddSubject(Clipper.Core.TPathsD(polygons1));
157+
AddClip(Clipper.Core.TPathsD(polygons2));
157158
Execute(ctIntersection,
158-
ClipperCore.TFillRule(fillRule), ClipperCore.TPathsD(result));
159+
Clipper.Core.TFillRule(fillRule), Clipper.Core.TPathsD(result));
159160
finally
160161
Free;
161162
end;
162163
end;
163164
//------------------------------------------------------------------------------
164165

165-
function DifferencePolygons(const polygons1, polygons2: TPathsD;
166-
fillRule: TFillRule): TPathsD;
166+
function DifferencePolygons(const polygons1, polygons2: Img32.TPathsD;
167+
fillRule: Img32.Vector.TFillRule): Img32.TPathsD;
167168
begin
168169
with TClipperD.Create do
169170
try
170-
AddPaths(ClipperCore.TPathsD(polygons1), ptSubject);
171-
AddPaths(ClipperCore.TPathsD(polygons2), ptClip);
171+
AddSubject(Clipper.Core.TPathsD(polygons1));
172+
AddClip(Clipper.Core.TPathsD(polygons2));
172173
Execute(ctDifference,
173-
ClipperCore.TFillRule(fillRule), ClipperCore.TPathsD(result));
174+
Clipper.Core.TFillRule(fillRule), Clipper.Core.TPathsD(result));
174175
finally
175176
Free;
176177
end;

Ext/SVGIconImageList/Image32/source/Img32.Draw.pas

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
(*******************************************************************************
44
* Author : Angus Johnson *
5-
* Version : 4.0 *
6-
* Date : 22 December 2021 *
5+
* Version : 4.2 *
6+
* Date : 30 May 2022 *
77
* Website : http://www.angusj.com *
88
* Copyright : Angus Johnson 2019-2021 *
99
* *
@@ -21,8 +21,7 @@ interface
2121
{.$DEFINE MemCheck} //for debugging only (adds a minimal cost to performance)
2222

2323
uses
24-
SysUtils, Classes, Types, Math, Img32, Img32.Vector,
25-
Img32.Transform; //experimental;
24+
SysUtils, Classes, Types, Math, Img32, Img32.Vector;
2625

2726
type
2827
TFillRule = Img32.Vector.TFillRule;
@@ -336,8 +335,8 @@ TScanLine = record
336335
PArgbs = ^TArgbs;
337336
TArgbs = array [0.. (Maxint div SizeOf(TARGB)) -1] of TARGB;
338337

339-
procedure ApplyClearType(img: TImage32;
340-
textColor: TColor32 = clBlack32; bkColor: TColor32 = clWhite32);
338+
procedure ApplyClearType(img: TImage32; textColor: TColor32 = clBlack32;
339+
bkColor: TColor32 = clWhite32);
341340
const
342341
centerWeighting = 5; //0 <= centerWeighting <= 25
343342
var
@@ -353,24 +352,23 @@ procedure ApplyClearType(img: TImage32;
353352
begin
354353
// Precondition: the background to text drawn onto 'img' must be transparent
355354

356-
// multiplication tables (see Img32.pas)
357355
// 85 + (2 * 57) + (2 * 28) == 255
358356
primeTbl := PByteArray(@MulTable[85 + centerWeighting *2]);
359357
nearTbl := PByteArray(@MulTable[57]);
360358
farTbl := PByteArray(@MulTable[28 - centerWeighting]);
361-
362-
SetLength(rowBuffer, img.Width+4);
363-
FillChar(rowBuffer[0], Length(rowBuffer) * SizeOf(TColor32), 0);
359+
SetLength(rowBuffer, img.Width +4);
364360

365361
for h := 0 to img.Height -1 do
366362
begin
367-
dst := PARGB(@img.Pixels[h * img.Width]);
368363
//each row of the image is copied into a temporary buffer ...
364+
//noting that while 'dst' (img.Pixels) is initially the source
365+
//it will later be destination (during image compression).
366+
dst := PARGB(@img.Pixels[h * img.Width]);
369367
src := PARGB(@rowBuffer[2]);
370368
Move(dst^, src^, img.Width * SizeOf(TColor32));
371369
srcArr := PArgbs(rowBuffer);
372370

373-
//using this buffer update the image ...
371+
//using this buffer compress the image ...
374372
w := 2;
375373
while w < img.Width do
376374
begin
@@ -391,7 +389,7 @@ procedure ApplyClearType(img: TImage32;
391389
end;
392390
end;
393391

394-
//The right 2/3 of the image can now be removed ...
392+
//Following compression the right 2/3 of the image is redundant
395393
img.Crop(Types.Rect(0,0, img.Width div 3, img.Height));
396394

397395
//currently text is white and the background is black
@@ -405,14 +403,15 @@ procedure ApplyClearType(img: TImage32;
405403
dst := PARGB(img.PixelBase);
406404
for h := 0 to img.Width * img.Height -1 do
407405
begin
408-
if dst.R > 0 then
406+
if dst.R = 0 then
407+
dst.Color := bkColor
408+
else
409409
begin
410-
//blend font and background colors ...
410+
//blend front (text) and background colors ...
411411
dst.R := (bg8_R + diff_R * dst.R) shr 8;
412412
dst.G := (bg8_G + diff_G * dst.G) shr 8;
413413
dst.B := (bg8_B + diff_B * dst.B) shr 8;
414-
end
415-
else dst.Color := 0;
414+
end;
416415
inc(dst);
417416
end;
418417
end;
@@ -421,7 +420,7 @@ procedure ApplyClearType(img: TImage32;
421420
// Other miscellaneous functions
422421
//------------------------------------------------------------------------------
423422

424-
////__Trunc: A very efficient Trunc() algorithm (ie rounds toward zero)
423+
////__Trunc: An efficient Trunc() algorithm (ie rounds toward zero)
425424
//function __Trunc(val: double): integer; {$IFDEF INLINE} inline; {$ENDIF}
426425
//var
427426
// exp: integer;
@@ -1028,13 +1027,23 @@ procedure Rasterize(const paths: TPathsD; const clipRec: TRect;
10281027
end;
10291028
frPositive:
10301029
begin
1030+
{$IFDEF REVERSE_ORIENTATION}
1031+
if accum < -0.002 then
1032+
byteBuffer[j] := Min(255, Round(-accum * 318));
1033+
{$ELSE}
10311034
if accum > 0.002 then
10321035
byteBuffer[j] := Min(255, Round(accum * 318));
1036+
{$ENDIF}
10331037
end;
10341038
frNegative:
10351039
begin
1040+
{$IFDEF REVERSE_ORIENTATION}
1041+
if accum > 0.002 then
1042+
byteBuffer[j] := Min(255, Round(accum * 318));
1043+
{$ELSE}
10361044
if accum < -0.002 then
10371045
byteBuffer[j] := Min(255, Round(-accum * 318));
1046+
{$ENDIF}
10381047
end;
10391048
end;
10401049
end;
@@ -2059,10 +2068,7 @@ procedure DrawPolygon_ClearType(img: TImage32; const polygons: TPathsD;
20592068
cr := TColorRenderer.Create(clBlack32);
20602069
try
20612070
if cr.Initialize(tmpImg) then
2062-
begin
20632071
Rasterize(tmpPolygons, tmpImg.bounds, fillRule, cr);
2064-
cr.NotifyChange;
2065-
end;
20662072
finally
20672073
cr.Free;
20682074
end;

0 commit comments

Comments
 (0)