From 3a2cfd397f752228f3e9b3f19b6515fbfc1a9dcb Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 23 Feb 2023 11:42:24 +0000 Subject: [PATCH] fpspreadsheet: Check compilation back to Laz 1.4.4/fpc 2.6.4. Update conditional defines in fps.inc. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8734 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/source/common/fpsfunc.pas | 3 +- .../source/common/fpsnumformat.pas | 15 ++++- .../source/common/fpsopendocument.pas | 15 +++-- .../source/common/fpspatches.pas | 26 ++++++++ .../fpspreadsheet/source/common/fpsutils.pas | 11 +++- .../fpspreadsheet/source/common/xlsxml.pas | 13 ++-- .../fpspreadsheet/source/common/xlsxooxml.pas | 13 +++- .../source/dataset/fpsdataset.pas | 62 ++++++++++++++++++- .../source/design/fpsvisualreg.pas | 2 +- components/fpspreadsheet/source/fps.inc | 13 ++++ .../source/visual/fpspreadsheetctrls.pas | 13 +++- .../source/visual/fpspreadsheetgrid.pas | 6 ++ 12 files changed, 168 insertions(+), 24 deletions(-) diff --git a/components/fpspreadsheet/source/common/fpsfunc.pas b/components/fpspreadsheet/source/common/fpsfunc.pas index 84ddbef04..eb3f77ee2 100644 --- a/components/fpspreadsheet/source/common/fpsfunc.pas +++ b/components/fpspreadsheet/source/common/fpsfunc.pas @@ -2284,7 +2284,8 @@ var Result := FindPart(searchString, s) > 0 // NOTE: FindPart currently supports only the wildcard '?' else - Result := SameStr(s, searchString); + Result := CompareStr(s, searchString) = 0; + //Result := SameStr(s, searchString); end else begin case ACell^.ContentType of diff --git a/components/fpspreadsheet/source/common/fpsnumformat.pas b/components/fpspreadsheet/source/common/fpsnumformat.pas index 745176ae8..470cb5ea2 100644 --- a/components/fpspreadsheet/source/common/fpsnumformat.pas +++ b/components/fpspreadsheet/source/common/fpsnumformat.pas @@ -9,10 +9,11 @@ -------------------------------------------------------------------------------} unit fpsNumFormat; -{$ifdef fpc} - {$mode objfpc}{$H+} -{$endif} +{$mode objfpc}{$H+} +{$include ../fps.inc} + {$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined} + interface uses @@ -3720,7 +3721,11 @@ begin '_': // Excel: Leave width of next character empty begin FToken := NextToken; + {$IFDEF DEFINE FPS_NO_NEW_UTF8_ROUTINES} uch := UTF8CharacterToUnicode(FCurrent, n); // wp: Why Unicode ??? + {$ELSE} + uch := UTF8CodePointToUnicode(FCurrent, n); + {$ENDIF} if n > 1 then begin AddElement(nftEmptyCharWidth, UnicodeToUTF8(uch)); @@ -3761,7 +3766,11 @@ begin Exit; end; else + {$IFDEF DEFINE FPS_NO_NEW_UTF8_ROUTINES} uch := UTF8CharacterToUnicode(FCurrent, n); + {$ELSE} + uch := UTF8CodePointToUnicode(FCurrent, n); + {$ENDIF} if n > 1 then begin AddElement(nftText, UnicodeToUTF8(uch)); diff --git a/components/fpspreadsheet/source/common/fpsopendocument.pas b/components/fpspreadsheet/source/common/fpsopendocument.pas index e9e8a53c0..a153493f4 100644 --- a/components/fpspreadsheet/source/common/fpsopendocument.pas +++ b/components/fpspreadsheet/source/common/fpsopendocument.pas @@ -23,14 +23,11 @@ NOTICE: Active define FPSpreadDebug in the project options to get a log during unit fpsOpenDocument; -{$ifdef fpc} - {$mode objfpc}{$H+} -{$endif} +{$mode objfpc}{$H+} +{$include ..\fps.inc} {$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined} -{$I ..\fps.inc} - interface uses @@ -323,9 +320,7 @@ uses LazLogger, {$ENDIF} StrUtils, Variants, LazFileUtils, URIParser, LazUTF8, - {$IFDEF FPS_VARISBOOL} - fpsPatches, - {$ENDIF} + {%H-}fpsPatches, fpsStrings, fpsStreams, fpsCrypto, fpsClasses, fpspreadsheet, fpsExprParser, fpsImages, fpsConditionalFormat; @@ -3923,7 +3918,11 @@ begin exit(false); Delete(s, p, MaxInt); + {$IFDEF FPS_NO_STRING_SPLIT} + sa := SplitString(s, ','); + {$ELSE} sa := s.Split(','); + {$ENDIF} arg1 := UnquoteStr(sa[0]); if Length(sa) > 1 then arg2 := UnquoteStr(sa[1]); diff --git a/components/fpspreadsheet/source/common/fpspatches.pas b/components/fpspreadsheet/source/common/fpspatches.pas index cd1c919c9..2c7024c37 100644 --- a/components/fpspreadsheet/source/common/fpspatches.pas +++ b/components/fpspreadsheet/source/common/fpspatches.pas @@ -52,6 +52,12 @@ type IntPtr = PtrInt; {$ENDIF} +{$IFDEF FPS_NO_STRING_SPLIT} +type + TStringArray = array of string; + +function SplitString(const AString: String; ASeparator: char): TStringArray; +{$ENDIF} implementation @@ -1731,5 +1737,25 @@ end; {$ENDIF} +{$IFDEF FPS_NO_STRING_SPLIT} +function SplitString(const AString: String; ASeparator: char): TStringArray; +var + L: TStrings; + i: Integer; +begin + L := TStringList.Create; + try + L.Delimiter := ASeparator; + L.StrictDelimiter := true; + L.DelimitedText := AString; + SetLength(Result, L.Count); + for i := 0 to L.Count-1 do + Result[i] := L[i]; + finally + L.Free; + end; +end; +{$ENDIF} + end. diff --git a/components/fpspreadsheet/source/common/fpsutils.pas b/components/fpspreadsheet/source/common/fpsutils.pas index ca1776cea..9fe5e9d50 100644 --- a/components/fpspreadsheet/source/common/fpsutils.pas +++ b/components/fpspreadsheet/source/common/fpsutils.pas @@ -13,12 +13,13 @@ unit fpsUtils; // when this same modification is in LazUtils of Laz stable {$mode objfpc}{$H+} +{$include fps.inc} interface uses Classes, SysUtils, TypInfo, - fpstypes; + fpsTypes; // Exported types type @@ -3243,7 +3244,11 @@ begin PEnd := P + Length(AText); while P < PEnd do begin + {$IFDEF FPS_NO_NEW_UTF8_ROUTINES} + chLen := UTF8CharacterLength(P); + {$ELSE} chLen := UTF8CodePointSize(P); + {$ENDIF} if (chLen = 1) and (P^ > #127) then begin ch := FPS_REPLACEMENT_CHAR; @@ -3268,7 +3273,11 @@ begin Result := true; repeat P := PChar(AText); + {$IFDEF FPS_NO_NEW_UTF8_ROUTINES} + i := FindInvalidUTF8Character(P, Length(AText), true); + {$ELSE} i := FindInvalidUTF8CodePoint(P, Length(AText), true); + {$ENDIF} if i >= 0 then begin Delete(AText, i+1, 1); diff --git a/components/fpspreadsheet/source/common/xlsxml.pas b/components/fpspreadsheet/source/common/xlsxml.pas index 880b49e20..81ada4135 100644 --- a/components/fpspreadsheet/source/common/xlsxml.pas +++ b/components/fpspreadsheet/source/common/xlsxml.pas @@ -14,10 +14,11 @@ LICENSE : For details about the license, see the file unit xlsxml; -{$ifdef fpc} - {$mode objfpc}{$H+} -{$endif} +{$mode objfpc}{$H+} +{$include ../fps.inc} + {$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined} + interface uses @@ -152,7 +153,7 @@ implementation uses StrUtils, DateUtils, Math, Variants, TypInfo, fpsStrings, fpsClasses, fpspreadsheet, fpsUtils, fpsNumFormat, fpsHTMLUtils, - fpsExprParser; + fpsExprParser, {%H-}fpsPatches; const FMT_OFFSET = 61; @@ -988,7 +989,11 @@ begin if valueStr = 'none' then Continue; end; + {$IFDEF FPS_NO_STRING_SPLIT} + sa := SplitString(valueStr, ' '); + {$ELSE} sa := valueStr.Split(' '); + {$ENDIF} lineColor := scNotDefined; lineStyle := -1; for j := 0 to High(sa) do begin diff --git a/components/fpspreadsheet/source/common/xlsxooxml.pas b/components/fpspreadsheet/source/common/xlsxooxml.pas index 0a11fc4d9..74bf1686f 100644 --- a/components/fpspreadsheet/source/common/xlsxooxml.pas +++ b/components/fpspreadsheet/source/common/xlsxooxml.pas @@ -27,10 +27,11 @@ AUTHORS: Felipe Monteiro de Carvalho, Reinier Olislagers, Werner Pamler unit xlsxooxml; -{$ifdef fpc} - {$mode objfpc}{$H+} -{$endif} +{$mode objfpc}{$H+} +{$include ../fps.inc} + {$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined} + interface uses @@ -4190,7 +4191,11 @@ procedure TsSpreadOOXMLReader.ReadVmlDrawing(ANode: TDOMNode; sa: TStringArray; i: Integer; begin + {$IFDEF FPS_NO_STRING_SPLIT} + sa := SplitString(AStyle, ','); + {$ELSE} sa := AStyle.Split(';'); + {$ENDIF} for i := 0 to High(sa) do if pos(AKey, sa[i]) = 1 then begin @@ -5685,7 +5690,9 @@ var begin book := FWorkbook as TsWorkbook; sheet := AWorksheet as TsWorksheet; + {$IF FPC_FullVersion >= 30000} lCell := Default(TCell); + {$IFEND} AppendToStream(AStream, ''); diff --git a/components/fpspreadsheet/source/dataset/fpsdataset.pas b/components/fpspreadsheet/source/dataset/fpsdataset.pas index a2b9f81e6..75d961ff8 100644 --- a/components/fpspreadsheet/source/dataset/fpsdataset.pas +++ b/components/fpspreadsheet/source/dataset/fpsdataset.pas @@ -53,13 +53,14 @@ unit fpsDataset; {$mode ObjFPC}{$H+} +{$I ../fps.inc} {$R ../../resource/fpsdatasetreg.res} {$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined} interface uses - Classes, SysUtils, Contnrs, DB, BufDataset_Parser, - fpSpreadsheet, fpsTypes, fpsUtils, fpsAllFormats; + Classes, SysUtils, DB, BufDataset_Parser, + fpSpreadsheet, fpsTypes, fpsUtils, {%H-}fpsAllFormats; type TRowIndex = Int64; @@ -335,6 +336,63 @@ begin NullMask^ := nullMask^ and not (1 shl m); end; +{$IFDEF FPS_NO_LAZUTF16} +// Here we borrow some code from newer Lazarus versions to make the package +// compile also with old versions. + +function UTF16CharacterLength(p: PWideChar): integer; +// returns length of UTF16 character in number of words +// The endianess of the machine will be taken. +begin + if p<>nil then begin + if (ord(p[0]) < $D800) or (ord(p[0]) > $DFFF) then + Result:=1 + else + Result:=2; + end else begin + Result:=0; + end; +end; + +function UTF16CharStart(P: PWideChar; Len, CharIndex: PtrInt): PWideChar; +// Len is the length in words of P. +// CharIndex is the position of the desired UnicodeChar (starting at 0). +var + CharLen: LongInt; +begin + Result:=P; + if Result=nil then Exit; + while (CharIndex>0) and (Len>0) do + begin + CharLen:=UTF16CharacterLength(Result); + dec(Len,CharLen); + dec(CharIndex); + inc(Result,CharLen); + end; + if (CharIndex<>0) or (Len<0) then + Result:=nil; +end; + +function UTF16Copy(const s: UnicodeString; StartCharIndex, CharCount: PtrInt): Unicodestring; +// returns substring +var + StartPos: PWideChar; + EndPos: PWideChar; + MaxBytes: PtrInt; +begin + StartPos:=UTF16CharStart(PWideChar(s),length(s),StartCharIndex-1); + if StartPos=nil then + Result:='' + else begin + MaxBytes:=PtrInt(PWideChar(s)+length(s)-StartPos); + EndPos:=UTF16CharStart(StartPos,MaxBytes,CharCount); + if EndPos=nil then + Result:=copy(s,StartPos-PWideChar(s)+1,MaxBytes) + else + Result:=copy(s,StartPos-PWideChar(s)+1,EndPos-StartPos); + end; +end; +{$ENDIF} { TsFieldDef } diff --git a/components/fpspreadsheet/source/design/fpsvisualreg.pas b/components/fpspreadsheet/source/design/fpsvisualreg.pas index b28b1b53d..12fbce6fc 100644 --- a/components/fpspreadsheet/source/design/fpsvisualreg.pas +++ b/components/fpspreadsheet/source/design/fpsvisualreg.pas @@ -17,7 +17,7 @@ implementation uses LResources, ActnList, PropEdits, {$IFDEF REGISTER_ALL_FILE_FORMATS} - fpsallformats, + {%H-}fpsallformats, {$ENDIF} fpspreadsheetctrls, fpspreadsheetgrid, fpspreadsheetchart, fpsactions; diff --git a/components/fpspreadsheet/source/fps.inc b/components/fpspreadsheet/source/fps.inc index c1721b47b..c4c819b17 100644 --- a/components/fpspreadsheet/source/fps.inc +++ b/components/fpspreadsheet/source/fps.inc @@ -48,4 +48,17 @@ The define is not needed for Lazarus versions >= 1.8 } {.$DEFINE FPS_NEED_STRINGHASHLIST} +{ In Lazarus 2.0+ some UTF8 routines in unit LazUTF8 were renamed from + UTF8Character... to UTF8CodePoint. Activate the following define when + the new routines are not available, i.e. for Lazarus version < 2.0. } +{.$DEFINE FPS_NO_NEW_UTF8_ROUTINES} + +{ Lazarus 1.8+ has unit LazUTF16 for special access to widestring. The following + define must be active when this unit is not available, i.e. for Lazarus + versions before 1.8.0. } +{.$DEFINE FPS_NO_LAZUTF16} + +{ Activate the following define if FPS does not have the string Split helper, + e.g. before v3.0 } +{.$DEFINE FPS_NO_STRING_SPLIT} diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas b/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas index 4cc172908..07ab70dd3 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas @@ -702,6 +702,10 @@ type function SpreadsheetFormatInClipboard: Boolean; +{$IF LCL_FullVersion < 1080000} +function ScalePPI(ALength: Integer): Integer; +{$IFEND} + implementation @@ -709,7 +713,7 @@ uses Types, Math, StrUtils, TypInfo, LCLType, LCLIntf, LCLProc, Dialogs, Forms, Clipbrd, fpsStrings, fpsCrypto, fpsReaderWriter, fpsUtils, fpsNumFormat, fpsImages, - fpsHTMLUtils, fpsExprParser, fpsConditionalFormat; + fpsHTMLUtils, fpsExprParser; var cfBiff8Format: Integer = 0; @@ -738,6 +742,13 @@ begin end; +{$IF LCL_FullVersion < 1080000} +function ScalePPI(ALength: Integer): Integer; +begin + Result := MulDiv(ALength, Screen.PixelsPerInch, 96); +end; +{$IFEND} + {------------------------------------------------------------------------------} { TsCellList } {------------------------------------------------------------------------------} diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas index e838665c7..b67ea3970 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas @@ -596,8 +596,10 @@ type defined by the rectangle. } property TextRotations[ALeft, ATop, ARight, ABottom: Integer]: TsTextRotation read GetTextRotations write SetTextRotations; + {$IF LCL_FullVersion >= 1080000} {@@ Pixel coordinates of the top-left corner of the grid's cell area} property TopLeftPx: TPoint read GetPxTopLeft; + {$IFEND} {@@ Parameter for vertical text alignment in the cell at column ACol and row ARow. } property VertAlignment[ACol, ARow: Integer]: TsVertAlignment read GetVertAlignment write SetVertAlignment; @@ -2766,7 +2768,11 @@ begin Canvas.Brush.Color := clRed; Canvas.Brush.Style := bsSolid; Canvas.Pen.Style := psClear; + {$IF LCL_FullVersion >= 1080000} commentSize := Scale96ToFont(COMMENT_SIZE); + {$ELSE} + commentSize := ScalePPI(COMMENT_SIZE); + {$IFEND} if IsRightToLeft then begin P[0] := Point(ARect.Left, ARect.Top);