@@ -96,6 +96,7 @@ interface
9696 TWIAPaperTypeSet = set of TWIAPaperType;
9797
9898const
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+
218226function THInchToSize (Unit_cm: Boolean; ASize: Integer): Single;
219227function THInchToStr (Unit_cm: Boolean; ASize: Integer): String;
220228function THInchToCm (ASize: Integer): Single;
221229function THInchToCmStr (ASize: Integer): String;
222230function THInchToInch (ASize: Integer): Single;
223231function THInchToInchStr (ASize: Integer): String;
224232function SizeToTHInch (Unit_cm: Boolean; ASize: Double): Integer;
233+
225234function PaperTypeNameAndSize (Unit_cm: Boolean; APaperType: TWIAPaperType): String;
235+ function PaperSizeToStr (Unit_cm: Boolean; APaperW, APaperH: Single): String;
226236
227237implementation
228238
229239uses SysUtils;
230240
231241function CalculatePaperSizeSet (Max_Width, Max_Height: Integer): TWIAPaperTypeSet;
232242var
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 ;
253269end ;
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+
255276function CalculatePaperSize (AWidth, AHeight: Integer): TWIAPaperType;
256277var
257278 i: TWIAPaperType;
279+ wMin, wMax,
280+ hMin, hMax: Integer;
258281
259282begin
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 ;
268297end ;
269298
299+ function CalculatePaperSize (AWidth, AHeight: Single): TWIAPaperType;
300+ begin
301+ Result:= CalculatePaperSize(Integer(Trunc(AWidth*1000 )), Integer(Trunc(AHeight*1000 )));
302+ end ;
303+
270304function THInchToSize (Unit_cm: Boolean; ASize: Integer): Single;
271305begin
272306 if Unit_cm
@@ -326,5 +360,11 @@ function PaperTypeNameAndSize(Unit_cm: Boolean; APaperType: TWIAPaperType): Stri
326360 end ;
327361end ;
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+
329369end .
330370
0 commit comments