Skip to content

Commit 32e3b2b

Browse files
committed
Changed page size handling to inches;
Changed page size handling to inches; Added GetPaperSize, GetPaperSizeMax, and Get/SetPaperRect methods; Added handling of error margins in dimensions
1 parent eb17361 commit 32e3b2b

4 files changed

Lines changed: 446 additions & 159 deletions

File tree

‎WIA_PaperSizes.pas‎

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ interface
9696
TWIAPaperTypeSet = set of TWIAPaperType;
9797

9898
const
99+
Unit_Str: array[Boolean] of String=('in', 'cm');
99100
PaperSizesWIA_MaxIndex = wptDIN_4B;
100101

101102
//Sizes of Papers in thousandths of an inch
@@ -213,23 +214,34 @@ interface
213214
(name:'DIN 4B'; w:200; h:282.8)
214215
*)
215216

216-
function CalculatePaperSizeSet(Max_Width, Max_Height: Integer): TWIAPaperTypeSet;
217-
function CalculatePaperSize(AWidth, AHeight: Integer): TWIAPaperType;
217+
var
218+
Paper_ErrMargin: Integer = 100;
219+
220+
function CalculatePaperSizeSet(Max_Width, Max_Height: Integer): TWIAPaperTypeSet; overload; //In TH Inches
221+
function CalculatePaperSizeSet(Max_Width, Max_Height: Single): TWIAPaperTypeSet; overload; //In Inches
222+
223+
function CalculatePaperSize(AWidth, AHeight: Integer): TWIAPaperType; overload; //In TH Inches
224+
function CalculatePaperSize(AWidth, AHeight: Single): TWIAPaperType; overload; //In Inches
225+
218226
function THInchToSize(Unit_cm: Boolean; ASize: Integer): Single;
219227
function THInchToStr(Unit_cm: Boolean; ASize: Integer): String;
220228
function THInchToCm(ASize: Integer): Single;
221229
function THInchToCmStr(ASize: Integer): String;
222230
function THInchToInch(ASize: Integer): Single;
223231
function THInchToInchStr(ASize: Integer): String;
224232
function SizeToTHInch(Unit_cm: Boolean; ASize: Double): Integer;
233+
225234
function PaperTypeNameAndSize(Unit_cm: Boolean; APaperType: TWIAPaperType): String;
235+
function PaperSizeToStr(Unit_cm: Boolean; APaperW, APaperH: Single): String;
226236

227237
implementation
228238

229239
uses SysUtils;
230240

231241
function CalculatePaperSizeSet(Max_Width, Max_Height: Integer): TWIAPaperTypeSet;
232242
var
243+
wMax,
244+
hMax,
233245
iSwap: Integer;
234246
i: TWIAPaperType;
235247

@@ -244,29 +256,51 @@ function CalculatePaperSizeSet(Max_Width, Max_Height: Integer): TWIAPaperTypeSet
244256
Max_Width:= iSwap;
245257
end;
246258

259+
wMax:= Max_Width+Paper_ErrMargin;
260+
hMax:= Max_Height+Paper_ErrMargin;
261+
247262
for i:=wptA4 to PaperSizesWIA_MaxIndex do
248263
begin
249264
//if the Paper is inside the Max Area then include it as selectable
250-
if (PaperSizesWIA[i].w <= Max_Width) and (PaperSizesWIA[i].h <= Max_Height)
265+
if (PaperSizesWIA[i].w <= wMax) and
266+
(PaperSizesWIA[i].h <= hMax)
251267
then Result:= Result + [i];
252268
end;
253269
end;
254270

271+
function CalculatePaperSizeSet(Max_Width, Max_Height: Single): TWIAPaperTypeSet;
272+
begin
273+
Result:= CalculatePaperSizeSet(Integer(Trunc(Max_Width*1000)), Integer(Trunc(Max_Height*1000)));
274+
end;
275+
255276
function CalculatePaperSize(AWidth, AHeight: Integer): TWIAPaperType;
256277
var
257278
i: TWIAPaperType;
279+
wMin, wMax,
280+
hMin, hMax: Integer;
258281

259282
begin
260283
Result:= wptCUSTOM;
284+
285+
wMin:= AWidth-Paper_ErrMargin;
286+
wMax:= AWidth+Paper_ErrMargin;
287+
hMin:= AHeight-Paper_ErrMargin;
288+
hMax:= AHeight+Paper_ErrMargin;
289+
261290
for i:=wptA4 to PaperSizesWIA_MaxIndex do
262291
begin
263-
//if the Width/Height is equals to a Paper then select it
264-
{ #note -oMaxM : It might be helpful to include a margin of error }
265-
if (PaperSizesWIA[i].w = AWidth) and (PaperSizesWIA[i].h = AHeight)
292+
//if the Width/Height is equals to a Paper (with a margin of error of 1/100 of Inches) then select it
293+
if (PaperSizesWIA[i].w in [wMin..wMax]) and
294+
(PaperSizesWIA[i].h in [hMin..hMax])
266295
then begin Result:= i; break; end;
267296
end;
268297
end;
269298

299+
function CalculatePaperSize(AWidth, AHeight: Single): TWIAPaperType;
300+
begin
301+
Result:= CalculatePaperSize(Integer(Trunc(AWidth*1000)), Integer(Trunc(AHeight*1000)));
302+
end;
303+
270304
function THInchToSize(Unit_cm: Boolean; ASize: Integer): Single;
271305
begin
272306
if Unit_cm
@@ -326,5 +360,11 @@ function PaperTypeNameAndSize(Unit_cm: Boolean; APaperType: TWIAPaperType): Stri
326360
end;
327361
end;
328362

363+
function PaperSizeToStr(Unit_cm: Boolean; APaperW, APaperH: Single): String;
364+
begin
365+
Result:= FloatToStrF(APaperW, ffFixed, 15, 2)+' x '+
366+
FloatToStrF(APaperH, ffFixed, 15, 2)+' '+Unit_Str[Unit_cm];
367+
end;
368+
329369
end.
330370

‎WIA_SettingsForm.pas‎

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,31 @@ procedure TWIASettingsSource.cbPaperTypeChange(Sender: TObject);
359359
edPaperW.Visible:= True;
360360
edPaperH.Visible:= True;
361361
gbPaperSize.Enabled:= True;
362-
edPaperW.Value:= THInchToSize(WIASettings_Unit_cm, WIAParams[WIASelectedItemIndex].PaperW);
363-
edPaperH.Value:= THInchToSize(WIASettings_Unit_cm, WIAParams[WIASelectedItemIndex].PaperH);
362+
363+
if WIASettings_Unit_cm
364+
then begin
365+
edPaperW.Value:= WIAParams[WIASelectedItemIndex].PaperW*2.54;
366+
edPaperH.Value:= WIAParams[WIASelectedItemIndex].PaperH*2.54;
367+
end
368+
else begin
369+
edPaperW.Value:= WIAParams[WIASelectedItemIndex].PaperW;
370+
edPaperH.Value:= WIAParams[WIASelectedItemIndex].PaperH;
371+
end;
364372
end;
365373
else begin
366374
gbPaperAlign.Enabled:= True;
367375
btPaperOrientation.Enabled:= True;
368376
gbPaperSize.Visible:= False;
369-
edPaperW.Value:= THInchToSize(WIASettings_Unit_cm, WIAParams[WIASelectedItemIndex].PaperW);
370-
edPaperH.Value:= THInchToSize(WIASettings_Unit_cm, WIAParams[WIASelectedItemIndex].PaperH);
377+
378+
if WIASettings_Unit_cm
379+
then begin
380+
edPaperW.Value:= WIAParams[WIASelectedItemIndex].PaperW*2.54;
381+
edPaperH.Value:= WIAParams[WIASelectedItemIndex].PaperH*2.54;
382+
end
383+
else begin
384+
edPaperW.Value:= WIAParams[WIASelectedItemIndex].PaperW;
385+
edPaperH.Value:= WIAParams[WIASelectedItemIndex].PaperH;
386+
end;
371387
end;
372388
end;
373389
end;
@@ -441,11 +457,13 @@ procedure TWIASettingsSource.SelectCurrentItem(AIndex: Integer);
441457
cbPaperType.Items.AddObject(rsFullsize, TObject(PtrUInt(wptMAX)));
442458
for paperI in PaperTypeSet do
443459
begin
444-
if (paperI <> wptMAX)
445-
then cbPaperType.Items.AddObject(PaperTypeNameAndSize(WIASettings_Unit_cm, paperI),
446-
TObject(PtrUInt(paperI)));
460+
if (paperI <> wptMAX) then
461+
begin
462+
cbPaperType.Items.AddObject(PaperTypeNameAndSize(WIASettings_Unit_cm, paperI),
463+
TObject(PtrUInt(paperI)));
447464

448-
if (paperI = AParams.PaperType) then cbSelected :=cbPaperType.Items.Count-1;
465+
if (paperI = AParams.PaperType) then cbSelected :=cbPaperType.Items.Count-1;
466+
end;
449467
end;
450468
cbPaperType.ItemIndex:=cbSelected;
451469

@@ -461,8 +479,15 @@ procedure TWIASettingsSource.SelectCurrentItem(AIndex: Integer);
461479
trHAlignChange(nil);
462480

463481
//Set Max,Current Values for Custom Paper Size
464-
edPaperW.MaxValue:= THInchToSize(WIASettings_Unit_cm, PaperSizeMaxWidth);
465-
edPaperH.MaxValue:= THInchToSize(WIASettings_Unit_cm, PaperSizeMaxHeight);
482+
if WIASettings_Unit_cm
483+
then begin
484+
edPaperW.MaxValue:= PaperSizeMaxWidth*2.54;
485+
edPaperH.MaxValue:= PaperSizeMaxHeight*2.54;
486+
end
487+
else begin
488+
edPaperW.MaxValue:= PaperSizeMaxWidth;
489+
edPaperH.MaxValue:= PaperSizeMaxHeight;
490+
end;
466491

467492
if (curItem^.ItemCategory = wicFEEDER) then
468493
begin
@@ -633,8 +658,15 @@ procedure TWIASettingsSource.StoreCurrentItemParams;
633658

634659
if (PaperType = wptCUSTOM) then
635660
begin
636-
PaperW:= SizeToTHInch(WIASettings_Unit_cm, edPaperW.Value);
637-
PaperH:= SizeToTHInch(WIASettings_Unit_cm, edPaperH.Value);
661+
if WIASettings_Unit_cm
662+
then begin
663+
PaperW:= edPaperW.Value/2.54;
664+
PaperH:= edPaperH.Value/2.54;
665+
end
666+
else begin
667+
PaperW:= edPaperW.Value;
668+
PaperH:= edPaperH.Value;
669+
end;
638670
end;
639671

640672
if btPaperOrientation.Down

‎changelog.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
WIAPASCAL CHANGE LOG
22
======================
3+
2026/08/07 Changed page size handling to inches;
4+
Added GetPaperSize, GetPaperSizeMax, and Get/SetPaperRect methods;
5+
Added handling of error margins in dimensions
6+
37
2026/07/07 Release 1.0.3;
48
Separated the graphics part from the package;
59
Added NO_UI package with no graphical dependencies;

0 commit comments

Comments
 (0)