From 1f76660947f84855582bd32786ecc0a61f466617 Mon Sep 17 00:00:00 2001 From: wp_xyz Date: Fri, 26 Apr 2024 13:08:40 +0200 Subject: [PATCH] Tools/icons_to_html: reads image sizes from files (by Roland Hahn) --- tools/icons_to_html/IconTable.lpi | 86 ++++++++++++++++++------------- tools/icons_to_html/main.lfm | 17 +++--- tools/icons_to_html/main.pas | 39 ++++++++++---- 3 files changed, 89 insertions(+), 53 deletions(-) diff --git a/tools/icons_to_html/IconTable.lpi b/tools/icons_to_html/IconTable.lpi index ff81a8f28f..fc1d07f832 100644 --- a/tools/icons_to_html/IconTable.lpi +++ b/tools/icons_to_html/IconTable.lpi @@ -19,8 +19,8 @@ - - + + @@ -75,12 +75,13 @@ - + - - + + + @@ -89,8 +90,12 @@ - - + + + + + + @@ -102,126 +107,135 @@ + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - - + - + - + - + - + - + - + - + - + - + - + + - + - + - + - + - + - + diff --git a/tools/icons_to_html/main.lfm b/tools/icons_to_html/main.lfm index bce483214d..d17a933388 100644 --- a/tools/icons_to_html/main.lfm +++ b/tools/icons_to_html/main.lfm @@ -9,13 +9,13 @@ object MainForm: TMainForm ClientWidth = 700 Constraints.MinHeight = 515 Constraints.MinWidth = 700 + Position = poScreenCenter + ShowHint = True + LCLVersion = '3.99.0.0' OnClose = FormClose OnCreate = FormCreate OnDropFiles = FormDropFiles OnShow = FormShow - Position = poScreenCenter - ShowHint = True - LCLVersion = '3.2.0.0' object DirectoryEdit: TDirectoryEdit AnchorSideLeft.Control = Owner AnchorSideTop.Control = sbtnLastDirs @@ -516,6 +516,8 @@ object MainForm: TMainForm object SynGutterMarks1: TSynGutterMarks Width = 24 MouseActions = <> + MaxExtraMarksColums = 0 + Options = [sgmoDeDuplicateMarksOnOverflow] end object SynGutterLineNumber1: TSynGutterLineNumber Width = 15 @@ -596,9 +598,9 @@ object MainForm: TMainForm Caption = 'Close' Images = ImageList ImageIndex = 6 - OnClick = bbtnCloseClick Spacing = 5 TabOrder = 6 + OnClick = bbtnCloseClick end object bbtnSave: TBitBtn AnchorSideTop.Control = bbtnClose @@ -616,9 +618,9 @@ object MainForm: TMainForm Enabled = False Images = ImageList ImageIndex = 5 - OnClick = bbtnSaveClick Spacing = 5 TabOrder = 5 + OnClick = bbtnSaveClick end object bbtnCreateHTML: TBitBtn AnchorSideTop.Control = bbtnPreview @@ -637,9 +639,9 @@ object MainForm: TMainForm Enabled = False Images = ImageList ImageIndex = 3 - OnClick = bbtnCreateHTMLClick Spacing = 5 TabOrder = 3 + OnClick = bbtnCreateHTMLClick end object bbtnPreview: TBitBtn AnchorSideTop.Control = bbtnSave @@ -655,12 +657,13 @@ object MainForm: TMainForm Enabled = False Images = ImageList ImageIndex = 4 - OnClick = bbtnPreviewClick TabOrder = 4 + OnClick = bbtnPreviewClick end object TaskDialog: TTaskDialog Buttons = <> RadioButtons = <> + QueryItemIndex = 0 Left = 96 Top = 64 end diff --git a/tools/icons_to_html/main.pas b/tools/icons_to_html/main.pas index fce1b30fd1..d28e515835 100644 --- a/tools/icons_to_html/main.pas +++ b/tools/icons_to_html/main.pas @@ -5,7 +5,7 @@ unit main; interface uses - Classes, SysUtils, Forms, Controls, Dialogs, StdCtrls, EditBtn, FileUtil, + Classes, SysUtils, Forms, FPImage, Controls, Dialogs, StdCtrls, EditBtn, FileUtil, LazUTF8, LazFileUtils, LCLIntf, LCLType, Buttons, Menus, IniFiles, SynEdit, SynHighlighterHTML; @@ -44,6 +44,7 @@ type procedure CreateHTML(HTMLLines: TStrings; Preview: Boolean); procedure ShowMsg(const AMsgCaption: String; const AMsg: String); procedure UpdateLastDirs(ImgDir: String; Delete: Boolean); + procedure GetPixSize(FileName: String; var PixWidth: Integer; var PixHeight: Integer); public end; @@ -241,6 +242,8 @@ var IcoFile: String; IcoSize: String; IcoName: String; + IcoWidth: Integer = 0; + IcoHeight: Integer = 0; DPos: Integer; IntDummy: Integer; i: Integer; @@ -273,16 +276,14 @@ begin for i := 0 to AllFileList.Count - 1 do begin IcoFile := ChangeFileExt(ExtractFileName(AllFileList.Strings[i]), ''); + GetPixSize(AllFileList.Strings[i], IcoWidth, IcoHeight); + IcoSize := IntToStr(IcoWidth); + DPos := LastDelimiter('_', IcoFile); - IcoSize := RightStr(IcoFile, Utf8Length(IcoFile) - DPos); - - if not TryStrToInt(IcoSize, IntDummy) then - IcoSize := ''; - - if IcoSize = '' then - IcoName := IcoFile + if TryStrToInt(RightStr(IcoFile, Utf8Length(IcoFile) - DPos), IntDummy) then + IcoName := Utf8Copy(IcoFile, 1, DPos - 1) else - IcoName := Utf8Copy(IcoFile, 1, DPos - 1); + IcoName := IcoFile; if Preview then IcoFileList.Add('file:///' + ImgDirectory + IcoFile) @@ -334,7 +335,7 @@ begin HTMLLines.Add(''); HTMLLines.Add(' '); HTMLLines.Add(' '); - HTMLLines.Add(' '); + HTMLLines.Add(' '); HTMLLines.Add(' '); HTMLLines.Add(' '); HTMLLines.Add(' '); @@ -489,6 +490,24 @@ begin Result := ''; end; +procedure TMainForm.GetPixSize(FileName: String; var PixWidth: Integer; var PixHeight: Integer); +var + stream: TStream; + reader: TFPCustomImageReaderClass; +begin + stream := TFileStream.Create(FileName, fmOpenRead + fmShareDenyWrite); + try + reader := TFPCustomImage.FindReaderFromStream(stream); + with reader.ImageSize(stream) do + begin + PixWidth := X; + PixHeight := Y; + end; + finally + stream.Free; + end; +end; + function CustomSortProc(List: TStringList; X1, X2: Integer): Integer; var P1, P2: Integer;
AppendixSize
Name