146 lines
4.2 KiB
Plaintext
146 lines
4.2 KiB
Plaintext
unit TSSafeUnitConverter;
|
||
interface
|
||
function CentimetersToPoints(value): real;
|
||
function EmusToPoints(value): real;
|
||
function InchesToPoints(value): real;
|
||
function LinesToPoints(value): real;
|
||
function MillimetersToPoints(value): real;
|
||
function PicasToPoints(value): real;
|
||
function PixelsToPoints(value): real; // TODO 不实现,与DPI有关
|
||
function TwipsToPoints(value): real;
|
||
|
||
// points -> other
|
||
function PointsToCentimeters(value): real;
|
||
function PointsToEmus(value): real;
|
||
function PointsToInches(value): real;
|
||
function PointsToLines(value): real;
|
||
function PointsToMillimeters(value);
|
||
function PointsToPicas(value);
|
||
function PointsToPixels(value); // TODO
|
||
function PointsToTwips(value): real;
|
||
|
||
// other
|
||
function HalfPointsToPoints(value): real;
|
||
function PointsToHalfPoints(value): real;
|
||
function EighthPointsToPoints(value): real;
|
||
function PercentToNumber(value): real;
|
||
function NumberToPercent(value): real;
|
||
function ToInt(value): integer;
|
||
|
||
implementation
|
||
uses TSUnitConverter;
|
||
|
||
function SafeConvert(value, convert_func): real;
|
||
begin
|
||
if ifNil(value) then return 0;
|
||
new_value := ifString(value) ? strToFloatDef(value, 0) : value;
|
||
return ##convert_func(new_value);
|
||
end;
|
||
|
||
function CentimetersToPoints(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.CentimetersToPoints));
|
||
end;
|
||
|
||
function EmusToPoints(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.EmusToPoints));
|
||
end;
|
||
|
||
function InchesToPoints(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.InchesToPoints));
|
||
end;
|
||
|
||
function LinesToPoints(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.LinesToPoints));
|
||
end;
|
||
|
||
function MillimetersToPoints(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.MillimetersToPoints));
|
||
end;
|
||
|
||
function PicasToPoints(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.PicasToPoints));
|
||
end;
|
||
|
||
function TwipsToPoints(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.TwipsToPoints));
|
||
end;
|
||
|
||
// points -> other
|
||
function PointsToCentimeters(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.PointsToCentimeters));
|
||
end;
|
||
|
||
function PointsToEmus(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.PointsToEmus));
|
||
end;
|
||
|
||
function PointsToInches(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.PointsToInches));
|
||
end;
|
||
|
||
function PointsToLines(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.PointsToLines));
|
||
end;
|
||
|
||
function PointsToMillimeters(value);
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.PointsToMillimeters));
|
||
end;
|
||
|
||
function PointsToPicas(value);
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.PointsToPicas));
|
||
end;
|
||
|
||
function PointsToTwips(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.PointsToTwips));
|
||
end;
|
||
|
||
// other
|
||
function HalfPointsToPoints(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.HalfPointsToPoints));
|
||
end;
|
||
|
||
function PointsToHalfPoints(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.PointsToHalfPoints));
|
||
end;
|
||
|
||
function EighthPointsToPoints(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.EighthPointsToPoints));
|
||
end;
|
||
|
||
function PercentToNumber(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.PercentToNumber));
|
||
end;
|
||
|
||
function NumberToPercent(value): real;
|
||
begin
|
||
return SafeConvert(value, thisFunction(TSUnitConverter.NumberToPercent));
|
||
end;
|
||
|
||
function ToInt(value): real;
|
||
begin
|
||
if ifnumber(value) then return integer(value);
|
||
if ifstring(value) then return strToIntDef(value, 0);
|
||
return 0;
|
||
end;
|
||
|
||
end.
|
||
|