You've already forked lazarus-ccr
fpspreadsheet: Cleaning up
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3167 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -96,7 +96,6 @@ procedure SplitFormatString(const AFormatString: String; out APositivePart,
|
||||
|
||||
function SciFloat(AValue: Double; ADecimals: Byte): String; overload;
|
||||
function SciFloat(AValue: Double; ADecimals: Byte; AFormatSettings: TFormatSettings): String; overload;
|
||||
//function TimeIntervalToString(AValue: TDateTime; AFormatStr: String): String;
|
||||
procedure MakeTimeIntervalMask(Src: String; var Dest: String);
|
||||
|
||||
// These two functions are copies of fpc trunk until they are available in stable fpc.
|
||||
@@ -115,7 +114,6 @@ function PtsToMM(AValue: Double): Double;
|
||||
function pxToPts(AValue, AScreenPixelsPerInch: Integer): Double;
|
||||
function PtsToPx(AValue: Double; AScreenPixelsPerInch: Integer): Integer;
|
||||
function HTMLLengthStrToPts(AValue: String): Double;
|
||||
//function HMTLLengthStrToPts(AValue: String): Double;
|
||||
|
||||
function HTMLColorStrToColor(AValue: String): TsColorValue;
|
||||
function ColorToHTMLColorStr(AValue: TsColorValue): String;
|
||||
@@ -591,10 +589,6 @@ var
|
||||
fmt: String;
|
||||
begin
|
||||
case ANumberFormat of
|
||||
{
|
||||
nfFmtDateTime:
|
||||
Result := SpecialDateTimeFormat(lowercase(AFormatString), AFormatSettings, false);
|
||||
}
|
||||
nfShortDateTime:
|
||||
Result := AFormatSettings.ShortDateFormat + ' ' + AFormatSettings.ShortTimeFormat;
|
||||
// In the DefaultFormatSettings this is: d/m/y hh:nn
|
||||
@@ -1078,6 +1072,147 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{ Excel's unit of row heights is "twips", i.e. 1/20 point.
|
||||
Converts Twips to points. }
|
||||
function TwipsToPts(AValue: Integer): Single;
|
||||
begin
|
||||
Result := AValue / 20;
|
||||
end;
|
||||
|
||||
{ Converts points to twips (1 twip = 1/20 point) }
|
||||
function PtsToTwips(AValue: Single): Integer;
|
||||
begin
|
||||
Result := round(AValue * 20);
|
||||
end;
|
||||
|
||||
{ Converts centimeters to points (72 pts = 1 inch) }
|
||||
function cmToPts(AValue: Double): Double;
|
||||
begin
|
||||
Result := AValue * 72 / 2.54;
|
||||
end;
|
||||
|
||||
{ Converts points to centimeters }
|
||||
function PtsToCm(AValue: Double): Double;
|
||||
begin
|
||||
Result := AValue / 72 * 2.54;
|
||||
end;
|
||||
|
||||
{ Converts inches to points (72 pts = 1 inch) }
|
||||
function InToPts(AValue: Double): Double;
|
||||
begin
|
||||
Result := AValue * 72;
|
||||
end;
|
||||
|
||||
{ Converts millimeters to points (72 pts = 1 inch) }
|
||||
function mmToPts(AValue: Double): Double;
|
||||
begin
|
||||
Result := AValue * 72 / 25.4;
|
||||
end;
|
||||
|
||||
{ Converts points to millimeters }
|
||||
function PtsToMM(AValue: Double): Double;
|
||||
begin
|
||||
Result := AValue / 72 * 25.4;
|
||||
end;
|
||||
|
||||
{ Converts pixels to points. }
|
||||
function pxToPts(AValue, AScreenPixelsPerInch: Integer): Double;
|
||||
begin
|
||||
Result := (AValue / AScreenPixelsPerInch) * 72;
|
||||
end;
|
||||
|
||||
{ Converts points to pixels }
|
||||
function PtsToPx(AValue: Double; AScreenPixelsPerInch: Integer): Integer;
|
||||
begin
|
||||
Result := Round(AValue / 72 * AScreenPixelsPerInch);
|
||||
end;
|
||||
|
||||
{ converts a HTML length string to points. The units are assumed to be the last
|
||||
two digits of the string }
|
||||
function HTMLLengthStrToPts(AValue: String): Double;
|
||||
var
|
||||
units: String;
|
||||
x: Double;
|
||||
res: Word;
|
||||
begin
|
||||
if (Length(AValue) > 1) and (AValue[Length(AValue)] in ['a'..'z', 'A'..'Z']) then begin
|
||||
units := lowercase(Copy(AValue, Length(AValue)-1, 2));
|
||||
val(copy(AValue, 1, Length(AValue)-2), x, res);
|
||||
// No hasseling with the decimal point...
|
||||
end else begin
|
||||
units := '';
|
||||
val(AValue, x, res);
|
||||
end;
|
||||
if res <> 0 then
|
||||
raise Exception.CreateFmt('No valid number or units (%s)', [AValue]);
|
||||
|
||||
if (units = 'pt') or (units = '') then
|
||||
Result := x
|
||||
else
|
||||
if units = 'in' then
|
||||
Result := InToPts(x)
|
||||
else if units = 'cm' then
|
||||
Result := cmToPts(x)
|
||||
else if units = 'mm' then
|
||||
Result := mmToPts(x)
|
||||
else if units = 'px' then
|
||||
Result := pxToPts(Round(x), ScreenPixelsPerInch)
|
||||
else
|
||||
raise Exception.Create('Unknown length units');
|
||||
end;
|
||||
|
||||
{ converts a HTML color string to a TsColorValue. For ods }
|
||||
function HTMLColorStrToColor(AValue: String): TsColorValue;
|
||||
begin
|
||||
if AValue = '' then
|
||||
Result := scNotDefined
|
||||
else
|
||||
if AValue[1] = '#' then begin
|
||||
AValue[1] := '$';
|
||||
Result := LongRGBToExcelPhysical(StrToInt(AValue));
|
||||
end else begin
|
||||
AValue := lowercase(AValue);
|
||||
if AValue = 'red' then
|
||||
Result := $0000FF
|
||||
else if AValue = 'cyan' then
|
||||
Result := $FFFF00
|
||||
else if AValue = 'blue' then
|
||||
Result := $FF0000
|
||||
else if AValue = 'purple' then
|
||||
Result := $800080
|
||||
else if AValue = 'yellow' then
|
||||
Result := $00FFFF
|
||||
else if AValue = 'lime' then
|
||||
Result := $00FF00
|
||||
else if AValue = 'white' then
|
||||
Result := $FFFFFF
|
||||
else if AValue = 'black' then
|
||||
Result := $000000
|
||||
else if (AValue = 'gray') or (AValue = 'grey') then
|
||||
Result := $808080
|
||||
else if AValue = 'silver' then
|
||||
Result := $C0C0C0
|
||||
else if AValue = 'maroon' then
|
||||
Result := $000080
|
||||
else if AValue = 'green' then
|
||||
Result := $008000
|
||||
else if AValue = 'olive' then
|
||||
Result := $008080;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ converts an rgb color value to a string as used in HTML code (for ods) }
|
||||
function ColorToHTMLColorStr(AValue: TsColorValue): String;
|
||||
type
|
||||
TRGB = record r,g,b,a: Byte end;
|
||||
var
|
||||
rgb: TRGB;
|
||||
begin
|
||||
rgb := TRGB(AValue);
|
||||
Result := Format('#%.2x%.2x%.2x', [rgb.r, rgb.g, rgb.b]);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
{******************************************************************************}
|
||||
{******************************************************************************}
|
||||
@@ -1442,145 +1577,5 @@ begin
|
||||
DateTimeToString(Result, FormatStr, DateTime, FormatSettings,Options);
|
||||
end;
|
||||
|
||||
{ Excel's unit of row heights is "twips", i.e. 1/20 point.
|
||||
Converts Twips to points. }
|
||||
function TwipsToPts(AValue: Integer): Single;
|
||||
begin
|
||||
Result := AValue / 20;
|
||||
end;
|
||||
|
||||
{ Converts points to twips (1 twip = 1/20 point) }
|
||||
function PtsToTwips(AValue: Single): Integer;
|
||||
begin
|
||||
Result := round(AValue * 20);
|
||||
end;
|
||||
|
||||
{ Converts centimeters to points (72 pts = 1 inch) }
|
||||
function cmToPts(AValue: Double): Double;
|
||||
begin
|
||||
Result := AValue * 72 / 2.54;
|
||||
end;
|
||||
|
||||
{ Converts points to centimeters }
|
||||
function PtsToCm(AValue: Double): Double;
|
||||
begin
|
||||
Result := AValue / 72 * 2.54;
|
||||
end;
|
||||
|
||||
{ Converts inches to points (72 pts = 1 inch) }
|
||||
function InToPts(AValue: Double): Double;
|
||||
begin
|
||||
Result := AValue * 72;
|
||||
end;
|
||||
|
||||
{ Converts millimeters to points (72 pts = 1 inch) }
|
||||
function mmToPts(AValue: Double): Double;
|
||||
begin
|
||||
Result := AValue * 72 / 25.4;
|
||||
end;
|
||||
|
||||
{ Converts points to millimeters }
|
||||
function PtsToMM(AValue: Double): Double;
|
||||
begin
|
||||
Result := AValue / 72 * 25.4;
|
||||
end;
|
||||
|
||||
{ Converts pixels to points. }
|
||||
function pxToPts(AValue, AScreenPixelsPerInch: Integer): Double;
|
||||
begin
|
||||
Result := (AValue / AScreenPixelsPerInch) * 72;
|
||||
end;
|
||||
|
||||
{ Converts points to pixels }
|
||||
function PtsToPx(AValue: Double; AScreenPixelsPerInch: Integer): Integer;
|
||||
begin
|
||||
Result := Round(AValue / 72 * AScreenPixelsPerInch);
|
||||
end;
|
||||
|
||||
{ converts a HTML length string to points. The units are assumed to be the last
|
||||
two digits of the string }
|
||||
function HTMLLengthStrToPts(AValue: String): Double;
|
||||
var
|
||||
units: String;
|
||||
x: Double;
|
||||
res: Word;
|
||||
begin
|
||||
if (Length(AValue) > 1) and (AValue[Length(AValue)] in ['a'..'z', 'A'..'Z']) then begin
|
||||
units := lowercase(Copy(AValue, Length(AValue)-1, 2));
|
||||
val(copy(AValue, 1, Length(AValue)-2), x, res);
|
||||
// No hasseling with the decimal point...
|
||||
end else begin
|
||||
units := '';
|
||||
val(AValue, x, res);
|
||||
end;
|
||||
if res <> 0 then
|
||||
raise Exception.CreateFmt('No valid number or units (%s)', [AValue]);
|
||||
|
||||
if (units = 'pt') or (units = '') then
|
||||
Result := x
|
||||
else
|
||||
if units = 'in' then
|
||||
Result := InToPts(x)
|
||||
else if units = 'cm' then
|
||||
Result := cmToPts(x)
|
||||
else if units = 'mm' then
|
||||
Result := mmToPts(x)
|
||||
else if units = 'px' then
|
||||
Result := pxToPts(Round(x), ScreenPixelsPerInch)
|
||||
else
|
||||
raise Exception.Create('Unknown length units');
|
||||
end;
|
||||
|
||||
{ converts a HTML color string to a TsColorValue. For ods }
|
||||
function HTMLColorStrToColor(AValue: String): TsColorValue;
|
||||
begin
|
||||
if AValue = '' then
|
||||
Result := scNotDefined
|
||||
else
|
||||
if AValue[1] = '#' then begin
|
||||
AValue[1] := '$';
|
||||
Result := LongRGBToExcelPhysical(StrToInt(AValue));
|
||||
end else begin
|
||||
AValue := lowercase(AValue);
|
||||
if AValue = 'red' then
|
||||
Result := $0000FF
|
||||
else if AValue = 'cyan' then
|
||||
Result := $FFFF00
|
||||
else if AValue = 'blue' then
|
||||
Result := $FF0000
|
||||
else if AValue = 'purple' then
|
||||
Result := $800080
|
||||
else if AValue = 'yellow' then
|
||||
Result := $00FFFF
|
||||
else if AValue = 'lime' then
|
||||
Result := $00FF00
|
||||
else if AValue = 'white' then
|
||||
Result := $FFFFFF
|
||||
else if AValue = 'black' then
|
||||
Result := $000000
|
||||
else if (AValue = 'gray') or (AValue = 'grey') then
|
||||
Result := $808080
|
||||
else if AValue = 'silver' then
|
||||
Result := $C0C0C0
|
||||
else if AValue = 'maroon' then
|
||||
Result := $000080
|
||||
else if AValue = 'green' then
|
||||
Result := $008000
|
||||
else if AValue = 'olive' then
|
||||
Result := $008080;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ converts an rgb color value to a string as used in HTML code (for ods) }
|
||||
function ColorToHTMLColorStr(AValue: TsColorValue): String;
|
||||
type
|
||||
TRGB = record r,g,b,a: Byte end;
|
||||
var
|
||||
rgb: TRGB;
|
||||
begin
|
||||
rgb := TRGB(AValue);
|
||||
Result := Format('#%.2x%.2x%.2x', [rgb.r, rgb.g, rgb.b]);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user