[Lazarus] Hi-DPI tweak of components

Ondrej Pokorny lazarus at kluug.net
Thu Jun 8 13:25:46 CEST 2023


Here is a more general proof for every possible combination of 
resolutions between 100% and 400% and for values [0..10000]:

program Project1;
uses Math;
const
   Resolutions: array[0..8] of Double = (1.00, 1.25, 1.50, 1.75, 2.00, 
2.50, 3.00, 3.50, 4.00);
var
   SourceResultion, TargetResolution: Double;
   I, F, ErrorCountInMiddleValue, ErrorCountAfterSecondScaling, 
MiddleValue: Integer;
begin
   ErrorCountInMiddleValue := 0;
   ErrorCountAfterSecondScaling := 0;
   for SourceResultion in Resolutions do
     for TargetResolution in Resolutions do
       if not SameValue(SourceResultion, TargetResolution) then
       begin
         for I := 0 to 10000 do
         begin
           F := I;
           // scale from source to target and back
           F := Round(F / SourceResultion * TargetResolution);
           F := Round(F * SourceResultion / TargetResolution);
           MiddleValue := F;
           if not SameValue(F, I) then
           begin
             Inc(ErrorCountInMiddleValue);
             // scale from source to target and back again
             F := Round(F / SourceResultion * TargetResolution);
             F := Round(F * SourceResultion / TargetResolution);

             if not SameValue(F, MiddleValue) then
             begin
               Writeln('Error after second scaling: ', I, ': ', F, ' 
SourceResultion:TargetResolution (', SourceResultion, ':', 
TargetResolution, ')');
               Inc(ErrorCountAfterSecondScaling);
             end;
           end;
         end;
       end;
   Writeln('ErrorCountInMiddleValue: ', ErrorCountInMiddleValue);
   Writeln('ErrorCountAfterSecondScaling: ', ErrorCountAfterSecondScaling);
   ReadLn;
end.

Ondrej



More information about the lazarus mailing list