Giter VIP home page Giter VIP logo

etheadev / svgiconimagelist Goto Github PK

View Code? Open in Web Editor NEW
298.0 46.0 93.0 257.25 MB

Four advanced components to simplify use of SVG images and SVG icons into ImageList: TSVGIconImage, TSVGIconImageCollection, TSVGIconVirtualImageList, TSVGIconImageList (for VCL and FMX). Choose the preferred engine to render SVG (Delphi Image32, SKIA4Delphi, Direct2D);

License: Apache License 2.0

Pascal 98.49% C++ 1.12% NASL 0.39%
delphi svg icons imagelist vcl fmx vcl-components fmx-component virtualimagelist vcl-fmx

svgiconimagelist's Introduction

SVGIconImageList License

Three engines to render SVG (Delphi Image32, Skia4Delphi, Direct2D wrapper) and four components to simplify use of SVG images (resize, fixedcolor, grayscale...)

Actual official version 4.1.2 (VCL+FMX)

Component Description
SVGIconImageCollectionComponentIcon.png TSVGIconImageCollection is collection of SVG Images for Delphi to provide a centralized list of images for SVGIconVirtualImageLists (only for VCL)
SVGIconVirtualImageListComponentIcon.png TSVGIconVirtualImageList is a special "virtual" ImageList for Delphi linked to an SVGIconImageCollection (only for VCL) to simplify use of SVG Icons (resize, opacity, grayscale and more...)
SVGIconImageComponentIcon.png TSVGIconImage is an extended Image component for Delphi (VCL+FMX) to show any SVG image directly or included into a an SVGIconImageList with all functionality (stretch, opacity, grayscale and more...)
SVGIconImageListComponentIcon.png TSVGIconImageList is an extended ImageList for Delphi (VCL+FMX) with an embedded SVG image collection: the VCL component is deprecated, we recommend to use SVGIconImageCollection + SVGIconVirtualImageList also for older Delphi versions!

Very important notice

WARNING: From version 4.0, TSVGIconVirtualImageList inherits from TVirtualImageList (using Delphi 10.3 to latest). For previous Delphi versions TSVGIconVirtualImageList inherits from TSVGIconImageListBase.

An important difference is that a TVirtualImageList may use and create only a subset of the images in the collection.

Although, the standard TVirtualImageList does not have the FixedColor, GrayScale, ApplyToRootOnly and Opacity properties, these properties exist at the TSVGIconImageCollection and they would be reflected on the linked TVirtualImageList, but if you change those properties at collection level, all the VirtualImageList linked changes!

For this reasons, now TSVGIconVirtualImageList have also FixedColor, GrayScale, ApplyToRootOnly and Opacity properties, so you can setup those properties only at VirtualImageList level, and you can share the same TSVGIconImageCollection from many VirtualImageList with different poperties, as you can see in the new SVGIconVirtualImageListDemo.

So, if you are using those components from Delphi 10.3, the recommended combination should be TSVGIconImageCollection + TSVGIconVirtualImageList.

Don't forget also the importance of PreserveItems when you have a large ImageCollection with many linked Actions. Without setting this property to "True", everytime you add or remove an icon in the collection, you have to check and change the ImageIndex of all the Actions.

Another feature available from Delphi 10.4 version, is that TSVGIconImageCollection inherits from TCustomImageCollection, so you can also use it with the TVirtualImage component and place SVG icons into the TControlList component, as explained here...

Choose your preferred SVG engine!

There are three implementation:

  • Native Delphi Image32 (default), uses Image32 library by Angus Johnson

  • Using Skia4Delphi library, a cross-platform 2D graphics API based on Google's Skia Graphics Library

  • A wrapper to the native Windows Direct2D implementation

You can read more details here.

Performance comparison

This table shows the performance of the three rendering engines tested with SVGExplorer, using a significant amount of icons from different sets, rendered at 128x128 pixels.

Count Icon set Image32 D2D Skia4Delphi
997 Font-Awesome 1265ms 1453ms 1172ms
654 Papirus 2750ms(1) 937ms 1266ms(1)
5366 Material-Design 11015ms 12001ms 10688ms

As you can see, the three engines perform differently depending on the icons and their complexity.

(1)Notice that Image32 and Skia4Delphi are the only engines capable of rendering blur effect (that is always slow to calculate): this is the reason of "slow" performance to render Papirus icons that contains blur effect.

Available from Delphi XE3 to Delphi 12 (VCL and FMX Platforms)

Delphi 12 Support

Related links: embarcadero.com - learndelphi.org

Sample image of VCL version

Sample.jpg

Sample image of FMX (Windows) version

SampleFMX.jpg

Sample images of the VCL SVGText-property editor (VCL and FMX)

SVGTextPropertyEditor.jpg

SVGTextPropertyEditorFMX.jpg

UTILITIES

The SVG Viewer Demo is useful to check the rendering quality of the engines available.

The SVG Icon Explorer utility is useful to explore and preview your svg image collections.

You can use SVG Shell Extensions if you want to see your icons directly into Windows Explorer or you want to edit them using a powerful SVG Text Editor.

DOCUMENTATION

Follow the guide in Wiki section to known how to use those components to modernize your Delphi VCL or FMX Windows applications scalable, colored and beautiful with few lines of code.

RELEASE NOTES

08 Jan 2024: version 4.1.2 (VCL+FMX)

  • Aligned To latest Image32
  • Added copy SVG to Clipboard into "Export to png" dialog
  • Updated Copyrights

09 Nov 2023: version 4.1.1 (VCL+FMX)

  • Aligned To Skia4Delphi 6.0.0
  • Added FMX Components to all platform
  • Fixed Demos for Delphi 12
  • Added SvgDisableEngineHint option

03 Sep 2023: version 4.1.0 (VCL+FMX)

  • Aligned Image32 Library released on 03/09/2023
  • Fixed demo (removed "obsolete" SVGColor uses)

24 Aug 2023: version 4.0.0 (VCL+FMX)

  • Removed old "native" engine TSVG
  • Updated to Skia4Delphi ver. 6.0.0
  • TSVGIconVirtualImageList inherits from TVirtualImageList (from D10.3 to actual version).
  • Added SVGIconVirtualImageListDemo to test multiple TSVGIconVirtualImageList in same form
  • Added support for Delphi 12

28 Feb 2023: version 3.9.6 (VCL+FMX)

  • Updated to Image32 ver. 4.4 (30 Jan 2023)
  • Updated to Skia4Delphi ver. 4.1.1 (26 Feb 2023)

13 Jan 2023: version 3.9.5 (VCL+FMX)

  • Updated Copyright 2023
  • Updated to Image32 ver. 4.3 (27 Sep 2022)
  • Updated to Skia4Delphi ver. 4.0.2

23 Oct 2022: version 3.9.4 (VCL+FMX)

  • FMX Component editor: changed selection for fixed color
  • Updated to Image32 ver. 4.3 (27 Sep 2022)

15 Sep 2022: version 3.9.3 (VCL+FMX)

  • Removed W11 Styles from Demo (available in Delphi only by Get-it)
  • Updated D11 packages to Delphi 11.2

28 Aug 2022: version 3.9.2 (VCL+FMX)

  • Fixed #240 TSVGGraphic.Assign
  • Updated to Image32 ver. 4.2 (28 July 2022)
  • Updated to Skia4Delphi 3.4.1 library
  • Fixed #241 Alignment from Source and Destination Items (FMX)

21 Jun 2022: version 3.9.1 (VCL+FMX)

  • Added support for other Delphi versions (VCL): D10 Seattle

08 May 2022: version 3.8.3 (VCL+FMX)

  • Updated to Skia4Delphi 3.4.0 library
  • SVGExplorer example moved under "Demo" folder

10 Apr 2022: version 3.8.2 (VCL+FMX)

  • Updated to Skia4Delphi 3.3.1 llibrary
  • Updated to Image32 4.11 library

29 Mar 2022: version 3.8.1 (VCL+FMX)

  • Fixed Aspect-Ratio for Skia engine
  • Updated SVGViewer
  • Updated Demos
  • Alignment to latest Skia4Delphi version

17 Mar 2022: version 3.8.0 (VCL+FMX)

  • Support for Delphi 11.1
  • Updated Library suffix for Delphi 10.4 and 11 to (auto)

09 Mar 2022: version 3.7.0 (VCL+FMX)

  • Support for Skia4Delphi 3.2.0 completed
  • Removed support for Cairo Engine
  • Fixed rendering with Image32

28 Feb 2022: version 3.6.0 (VCL + FMX)

  • Support for Skia4Delphi also in FMX platforms

26 Feb 2022: version 3.5.2 (VCL+FMX)

  • Fixed rendering with FMX-Image32

23 Feb 2022: version 3.5.1 (VCL+FMX)

  • Updated Image32 Library to 4.1.0 version
  • Updated support to Skia4Delphi 3.1.0

19 Feb 2022: version 3.5.0 (VCL+FMX)

  • Updated Image32 Library to 4.0.2 version
  • Updated support to Skia4Delphi 3.0.3
  • Fixed SVGText Editor
  • Fixed some Skia4Delphi SVG rendering

14 Feb 2022: version 3.4.0 (VCL+FMX)

  • Updated Image32 Library to 4.0.1 version
  • Added support to Skia4Delphi 3.0
  • Fixed some Image32 drawing problem

13 Jan 2022: version 3.3.0 (VCL+FMX)

  • Updated Image32 library to 4.0.0 version
  • Added a set of playing cards svg examples
  • Fixed Image32 drawing problem with "playing cards"

24 Nov 2021: version 3.2.0 (VCL+FMX)

  • Component Editors uses IDE themes (light, dark...) and style
  • Fixed available components into palette when working with mobile platforms

05 Nov 2021: version 3.1.1 (VCL+FMX)

  • Fixed Image32 drawing problem in FMX
  • Added Export to multiple png files to Component Editor

31 Oct 2021: version 3.1.0 (VCL+FMX)

  • Updated Image32 library to 3.4.1 version
  • Added Skia4Delphi engine (not complete)

28 Aug 2021: version 3.0.0 (VCL+FMX)

  • Updated Packages for Delphi 11
  • Updated some documentation (Images and Wiki)

24 Aug 2021: version 2.5.0 (VCL+FMX)

  • Aligned to Image32 library ver.3.1

22 Jul 2021: version 2.4.0 (VCL+FMX)

  • Updated and aligned to Image32 ver.3 library
  • Added packages for Delphi 11 Alexandria

18 Jul 2021: version 2.3.1 (VCL+FMX)

  • Fixed rendering files with color defined by 8 digits

17 Jul 2021: version 2.3.0 (VCL+FMX)

  • Added new engine: Image32 library by Angus Johnson (VCL+FMX)
  • Image32 is now the default native Delphi engine
  • Added support for Android and iOS platforms (by Image32 engine)
  • Added support for backward Delphi versions (from XE3)
  • Added demo to compare the four engines (SVGViewer)
  • Fixed rendering "centered" in SVGIconImage for Cairo engine.
  • Warning: changed TSVGIconImage component ancestor from TCustomControl to TGraphicControl

18 Apr 2021: version 2.2.6 (VCL+FMX)

  • Added new ApplyFixedColorToRootOnly property
  • Added demo for new TControlList component (only for D10.4.2)

22 Feb 2021: version 2.2.5 (VCL+FMX)

  • Added export to PNG option into Component editor

23 Jan 2021: version 2.2.4 (VCL+FMX)

  • Fixed #156 Stretch for SVGIconImage
  • Fixed #157 SVGIconImage gets correct image from VirtualImageList

17 Jan 2021: version 2.2.3 (VCL+FMX)

  • Fixed #151 Antialiasing problems
  • Fixed settings of different Width and Height into editor
  • Fixed preview of icon with different Height and Width into editor

24 Dec 2020: version 2.2.2 (VCL+FMX)

  • Added Width, Height and Zoom property for FMX components
  • Redesigned FMX component editor
  • Fixed VCL component editor

08 Dec 2020: version 2.2.1 (VCL+FMX)

  • Added 64bit platforms for packages
  • Minor fixes (empty except blocks)
  • Fixed TSVGIconImage inherited color
  • Fixed repaint for FMX version

23 Sep 2020: version 2.2.0 (VCL+FMX)

  • Added "Cairo" SVG Engine
  • Added AntialiasColor to perfect antialias effect
  • Added ImageIndex property editor for SVGIconImage
  • Added FixedColor and GrayScale to TSVGIconImage component

16 Sep 2020: version 2.1.1 (VCL) 2.1.0 (FMX)

  • Fixed issues (#110, #111, #113)
  • Editing SVG text in editor shows errors without losing content

04 Sep 2020: version 2.1.0 (VCL) 1.5.1 (FMX)

  • Added preview for icons when loading svg files
  • Fixed many issue (#81, #86, #87, #88, #91, #94, #103...)
  • Refactoring parsing XML to increase performances (using XmlLite)

26 Aug 2020: version 2.0 (VCL) 1.5.0 (FMX)

  • Added factory to choose engine
  • Added interface to use alternative Third-party SVG engine
  • Redesigned component editor to support Categories for icons
  • New support for native VirtualImageList (from D10.3)
  • StoreAsText icons to dfm by default (and unique mode)
  • Fixed many issues (from #35 to #72) Take care of TSVGIconVirtualImageList.Collection renamed to SVGIconVirtualImageList.ImageCollection.

17 Aug 2020: version 1.9 (VCL+FMX)

  • FixedColor changed from TSVGColor to TColor
  • Fixed assign FixedColor to icon in component editor
  • Updated component editor to use TColorBox

13 Aug 2020: version 1.8 (VCL+FMX)

  • Complete refactoring for full support of High-DPI
  • New SVGIconImageCollection component
  • New SVGIconVirtualImageList component
  • Redesign of SVGIconImageList component and Component Editor
  • Demo updated to test multi-monitor with different DPI
  • Fixed issue #20: Coordinates in double (PaintTo methods)
  • Fixed issue #25: Transform matrix is wrongly parsed
  • Fixed issue #26: Error in CalcMartrix
  • Fixed issue #27: TSVGRadialGradient.ReadIn does not read the gradientTransform matrix
  • Fixed issue #28: Colors should be reversed in TSVGRadialGradient
  • Fixed issue #29: Scaling should be based on ViewBox width/height
  • Fixed issue #31: Empty svg properties cause exceptions
  • Fixed issue #33: "fill-rule' presentation attribute is not processed
  • Fixed issue #34: Exception text elements cause exceptions

05 Aug 2020: version 1.7 (VCL+FMX)

  • Added DPIChanged method
  • Enhanced SVGExplorer
  • Fixed issue #20: replaced Double with Single
  • Fixed issue #19 and 18#: Load/SaveToStream inefficient and encoding inconsistency
  • Fixed issue #17: Wrong conversion from pt to px
  • Fixed issue #14: scaling problem
  • Fixed issue #11: Incompatible with Drag-Drop of TImageList
  • Fixed issue #6: Rendering of some SVG images is incorrect

15 July 2020: version 1.6 (VCL+FMX)

  • Fixed rendering on TButton! (VCL)
  • Fixed "Apply" into ImageEditor (VCL)
  • Added reformat XML to ImageEditor (VCL)
  • Added utility to explore icons into disk/folder (SVGExplorer)
  • Fixed inherited color drawing (SVG)
  • Fixed storing properties into dfm in binary mode (VCL)
  • Fixed storing for some properties (don't store default values)

13 June 2020: versione 1.5 (VCL+FMX)

  • Added support for DisabledGrayScale and DisabledOpacity as in VirtualImageList
  • Fixed drawing disabled icons also with VCLStyles active

09 June 2020: versione 1.4 (VCL+FMX)

  • Added GrayScale and FixedColor to ImageList for every Icons
  • Added GrayScale and FixedColor for single Icon
  • Added some complex svg demo images
  • Updated demos

06 June 2020: version 1.3 (VCL+FMX)

  • Added property editor for TSVGIconImage.SVGText and TSVGIconItem.SVGText
  • Fixed some drawing problems with transform attribute
  • Fixed rescaling icons when monitor DPI changes

28 May 2020: version 1.2 (VCL+FMX)

  • Complete support of Delphi 10.4
  • Added support for other Delphi versions (VCL): DXE6, DXE8, D10.1
  • Added position memory of component editor
  • Fixed Issue: Icon Editor not keeping added icons
  • Fixed Issue: SVG with exponent notation does not parse correctly and affects image display

25 May 2020: version 1.1 (VCL+FMX)

  • Added the component TSVGIconImageListFMX with advanced component editor.
  • Added the component TSVGIconImageFMX to show SVG into a TImage.
  • Demos to show how they works.
  • Very high performance for building hundreds of icons.

24 May 2020: first version 1.0 (VCL)

  • Added the component TSVGIconImageList with advanced component editor.
  • Added the component TSVGIconImage to show SVG into a TImage.
  • Demos to show how they works.
  • Very high performance for building hundreds of icons.
  • Support from Delphi 10.2 to 10.4 Sydney (other Delphi versions coming soon)

THANKS TO

These components use the followin libraries:

  • SVG library by Martin Walter (Original version (c) 2005, 2008) with license:
    Use of this file is permitted for commercial and non-commercial. Use, as long as the author is credited.
    home page: http://www.mwcs.de email: [email protected]
    This library is included in the svg folder of this project.
  • Image32 library by Angus Johnson These files are included in the Image32/Source and Image32/source/Image32_SVG folders
  • Skia4Delphi Library by the autohors These files are included in the Skia4Delphi/Source folder

Many thanks to Vincent Parrett and Kiriakos Vlahos for their great contibution.

TSVGIconImageList and TSVGIconImage are similar to TSVGImageList and TSVGImage included into project: https://github.com/ekot1/DelphiSVG.git but those versions are more efficient in performances, with many fixes added, plus some features like SVGText property, store icons in Text format into dfm, GrayScale and FixedColor, VirtualImageList support and more...

TSVGIconImageListFMX and TSVGIconImageFMX are similar to TIconFontsImageListFMX and TIconFontsImage included into similar project made by Ethea for Icon Fonts: https://github.com/EtheaDev/IconFontsImageList

svgiconimagelist's People

Contributors

ange007 avatar atkins126 avatar birbilis avatar carlobarazzetta avatar jensmertelmeyer avatar luebbe avatar mazighusdz avatar pyscripter avatar vincentparrett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svgiconimagelist's Issues

The transform attribute is not parsed correctly

There are two issues:
Consider for example the following transform from the lion.svg:

<g transform="rotate(10) scale (1) translate (100,10)">

The first issue is that due to the space after translate, the translate function is not applied.
The second and more serious issue is that the 3 transformations are applied in the wrong order.

Wrong conversion from pt to px

In SvgParse.pas there is the following code:

function GetFactor(const SVGUnit: TSVGUnit): TFloat;
begin
  case SVGUnit of
    suPX: Result := 1;
    suPT: Result := 1.25;
    suPC: Result := 15;
    suMM: Result := 10;
    suCM: Result := 100;
    suIN: Result := 25.4;
    suEM: Result := 1;
    suEX: Result := 1;
    suPercent: Result := 1;
    else
      Result := 1;
  end;
end;

The conversion from pt to px should be 1.3333 = 4/3 (96/72) instead of 1.25. I have not checked the other conversions.

On the demo

On the demo after changing to any theme memory leak. D10.2.3
Screenshot - 26_05_2020 , 08_59_45

Problem rendering of ImageList vs SVGIconImage

image

I've notice that the ImageList don't render properly the antialias effect to the target surface, as you can see into the image.
The difference is that SVGIconImage calls SVG.PaintTo(HDC...) instead of imagelist calls PaintTo(Graphics: TGPGraphics.
both uses Graphics.SetSmoothingMode(SmoothingModeAntiAlias) but it seems to render in different way.
Do you know why?

About using native VirtualImageList

Hi guys,
in the last commit (August 18 - 22:44) I made some changes to TSVGIconImageCollection: now it inherits from TCustomImageCollection instead of TComponent and implements all required method (only from D10.3).
With this change it is now possible to use a native VirtualImageList connected to the collection, without breaking the use with SVGIconVirtualImageList.
To implement TSVGIconImageCollection.GetBitmap, I have moved bitmap creation from SVGIconImageListBase to SVGIconItems (maybe not the best place ...).
I have some doubts if this modification can be useful, because the use of a native VirtualImageList does not bring particular advantages compared to the use of the SVGIconVirtualImageList (indeed it is not able to use Grayscale, Opacity, FixedColor ...).
What do you think @pyscripter and @vincentparrett ?
I also deleted SVGToIcon24 too ... do we need it?

Quadratic Bezier curves T command handling is incorrect

Test with:

<?xml version="1.0" standalone="no"?>
<svg width="12cm" height="6cm" viewBox="0 0 1200 600"
     xmlns="http://www.w3.org/2000/svg" version="1.1">
  <title>Example quad01 - quadratic Bรฉzier commands in path data</title>
  <desc>Picture showing a "Q" a "T" command,
        along with annotations showing the control points
        and end points</desc>
  <rect x="1" y="1" width="1198" height="598"
        fill="none" stroke="blue" stroke-width="1" />

  <path d="M200,300 Q400,50 600,300 T1000,300"
        fill="none" stroke="red" stroke-width="5"  />
  <!-- End points -->
  <g fill="black" >
    <circle cx="200" cy="300" r="10"/>
    <circle cx="600" cy="300" r="10"/>
    <circle cx="1000" cy="300" r="10"/>
  </g>
  <!-- Control points and lines from end points to control points -->
  <g fill="#888888" >
    <circle cx="400" cy="50" r="10"/>
    <circle cx="800" cy="550" r="10"/>
  </g>
  <path d="M200,300 L400,50 L600,300
           L800,550 L1000,300"
        fill="none" stroke="#888888" stroke-width="2" />
</svg>

Exception text elements cause exceptions

An Exception is raised in TSVGTSpan.ReadTextNodes if the text element has no text.

Solution:
Add exception handling in TSVGTSpan.ReadTextNodes:

procedure TSVGTSpan.ReadTextNodes(const Node: IXMLNode);
begin
  // empty text nodes would raise exception
  try
    FText := Node.Text;
  except
  end;

"fill-rule' presentation attribute is not processed

See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule.

Test with:

<svg viewBox="-10 -10 220 120" xmlns="http://www.w3.org/2000/svg">
  <!-- Default value for fill-rule -->
  <polygon fill-rule="nonzero" stroke="red"
   points="50,0 21,90 98,35 2,35 79,90"/>

  <!--
  The center of the shape has two
  path segments (shown by the red stroke)
  between it and infinity. It is therefore
  considered outside the shape, and not filled.
  -->
  <polygon fill-rule="evenodd" stroke="red"
   points="150,0 121,90 198,35 102,35 179,90"/>
</svg>

Separate storage from drawing of icons

Excellent work!

An ImageList is typically shared by more than one forms. In a per-monitor DPI scaled appliation, every form should have its own imagelist so that icons are scaled according to the monitor the form resides. As it stands that would lead to icon duplication.

Delphi has solved this issue by having a separate TImageCollection that handles the storage of the icons and a VirtualImageList that draws icons from an ImageCollection appropriately scaled.

I suggest something similar. a TSvgIconCollection that stores the svg icons and a TVirtualImageList that transforms a subset of icons from a TSvgIconCollection into a scaled ImageList.

FixedColor and memory leak

Neither FixedColor property nor icon fixed color does work in the latest version 1.8.0. Also if you change the icon fixed color there is a memory leak: "An unexpected memory leak has occured. The unexpected small block leaks are: 21-28 bytes: AnsiString x 1".

The color was working in previous version. The memory leak was already there.

Error in CalcMartrix

When you apply multiple transformations you pre-multiply the new one with the old one. See for example CalcRootMatrix where it is done correctly. However in TSVGMatrix.CalcMatrix it is done the wrong way (post-multiply the new matrix).

You need to change:

CompleteMatrix := CompleteMatrix * NewMatrix;
to
CompleteMatrix := NewMatrix * CompleteMatrix;

and
LMatrix := LMatrix * NewMatrix;
to
LMatrix := NewMatrix * LMatrix;

Also the "fix"

          //Fix for transform:translate with rescaling
          NewMatrix.m31 := NewMatrix.m31 * ADX;
          NewMatrix.m32 := NewMatrix.m32 * ADY;

is just wrong. Please remove.

Finally CalculateMatrices and CalcMatrix do not need any arguments. AX, AY, ADX, AD are taken care of by the transformations in CalcRootMatrix.

You can test the above with the attached sgv.
Back3.zip

Problem compiling with 10.1

With 10.1 I have an error at line 73 in SVGCommon: "Invalid typecast"

Result := WinApi.GDIPAPI.MakeRect(Single(Left), Top, Width, Height);

SVG with exponent notation does not parse correctly and affects image display

SVG Image paths can contain floating point values notated as exponential, but TSVGPath.SeparateValues in SVG.pas does not account for such data. Example: this is a valid path:
<path fill="#004C75" d="M23.8,34 L3.4,34 C1.53,34 -5.32907052e-15,32.47 -5.32907052e-15,30.6 L-5.32907052e-15,3.4 C-5.32907052e-15,1.53 1.53,0 3.4,0 L23.8,0 C25.67,0 27.2,1.53 27.2,3.4 L27.2,30.6 C27.2,32.47 25.67,34 23.8,34 Z M3.4,3.4 L3.4,3.4 L3.4,30.6 L23.8,30.6 L23.8,3.4 L3.4,3.4 Z"/>

Suggested change to handle exponential:

function TSVGPath.SeparateValues(const ACommand: Char; const S: string): TStrings;
var
  NumberStr: string;
  C: Char;
  HasDot: Boolean;
  HasExp: Boolean;
begin
  NumberStr := '';
  HasDot := False;
  HasExp := False;

  Result := TStringList.Create;

  for C in S do
  begin
    case C of
      '.':
        begin
          if HasDot then
          begin
            HasDot := C = '.';
            Result.Add(NumberStr);
            NumberStr := C;
          end
          else
          begin
            NumberStr := NumberStr + C;
            HasDot := True;
          end;
        end;
      '0'..'9':
        begin
          NumberStr := NumberStr + C;
        end;
      '+', '-':
        begin
          if NumberStr <> '' then
          begin
            if not HasExp then begin
              Result.Add(NumberStr);
              HasDot := False;
            end else
              NumberStr := NumberStr + C;
          end;
          if not HasExp then
            NumberStr := C;
        end;
      'E', 'e':
        begin
          HasExp := True;
          NumberStr := NumberStr + C;
        end;
      ' ', #9, #$A, #$D:
        begin
          if NumberStr <> '' then
          begin
            Result.Add(NumberStr);
            NumberStr := '';
            HasDot := False;
          end;
        end;
    end;
  end;
  if NumberStr <> '' then
  begin
    Result.Add(NumberStr);
  end;

  Result.Insert(0, ACommand);

  if Result.Count > 0 then
  begin
    if ACommand.IsInArray(['M', 'm', 'L', 'l', 'H', 'h', 'V', 'v',
      'C', 'c', 'S', 's', 'Q', 'q', 'T', 't', 'A', 'a']) then
    begin
      PrepareMoveLineCurveArc(ACommand, Result);
    end
    else if (ACommand = 'Z') or (ACommand = 'z') then
    begin
      while Result.Count > 1 do
      begin
        Result.Delete(1);
      end;
    end;
  end;
end;

Sample SVG image to validate the correction:

<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36">
  <g fill="none" transform="translate(4 1)">
    <path fill="#D1DBCA" d="M3.4,1.7 L23.8,1.7 C24.82,1.7 25.5,2.38 25.5,3.4 L25.5,30.6 C25.5,31.62 24.82,32.3 23.8,32.3 L3.4,32.3 C2.38,32.3 1.7,31.62 1.7,30.6 L1.7,3.4 C1.7,2.38 2.38,1.7 3.4,1.7 Z"/>
    <path fill="#004C75" d="M23.8,34 L3.4,34 C1.53,34 -5.32907052e-15,32.47 -5.32907052e-15,30.6 L-5.32907052e-15,3.4 C-5.32907052e-15,1.53 1.53,0 3.4,0 L23.8,0 C25.67,0 27.2,1.53 27.2,3.4 L27.2,30.6 C27.2,32.47 25.67,34 23.8,34 Z M3.4,3.4 L3.4,3.4 L3.4,30.6 L23.8,30.6 L23.8,3.4 L3.4,3.4 Z"/>
    <path fill="#004C75" d="M13.6,8.5 L20.4,8.5 L20.4,11.9 L13.6,11.9 L13.6,8.5 Z M6.8,8.5 L10.2,8.5 L10.2,11.9 L6.8,11.9 L6.8,8.5 Z M13.6,15.3 L20.4,15.3 L20.4,18.7 L13.6,18.7 L13.6,15.3 Z M6.8,15.3 L10.2,15.3 L10.2,18.7 L6.8,18.7 L6.8,15.3 Z M13.6,22.1 L20.4,22.1 L20.4,25.5 L13.6,25.5 L13.6,22.1 Z M6.8,22.1 L10.2,22.1 L10.2,25.5 L6.8,25.5 L6.8,22.1 Z"/>
  </g>
</svg>

Percentages are not handled correctly

Specifying x, y r etc. as percentages is not handed at all except for the top level where is not used in stand-alone svgs.

For example:

<svg viewBox="0 0 64 64" height="64" width="64" 
  xmlns="http://www.w3.org/2000/svg">
  <circle cx="25%" cy="25%" r="25%" style="fill:red;stroke:#000000;stroke-width:0.1"/>
  <circle cx="75%" cy="75%" r="25%" style="fill:blue;stroke:#000000;stroke-width:0.1" />
</svg>

is not properly rendered. The percentages are interpreter as pixels.

Fixing this requires some substantial changes. I can submit a PR for this but could you please first review and commit #32 , since it is not a good idea to have a massive PR.

See this link about how percentages should be handled

Icon Categories

It would be nice if TSVGIconItem contained a Category field (possibly empty) and the property editors allowed for filtering by Category. (Like Actions or the Delphi ImageCollection)

MultiSystem FMX

Hi.
Do you have plans for a support another system in FMX version?
Or used SVG library work only on Windows?

FixedColor is not working

FixedColor does not work. Images are always black. Even if you set both FixedColors to white.

image

Also the editor is not showing the color.

image

Scaling should be based on ViewBox width/height.

In svgs you have the viewport and the viewbox (See https://webdesign.tutsplus.com/tutorials/svg-viewport-and-viewbox-for-beginners--cms-30844).

The ViewPort is specified by the width and height attributes. This is the actual width and height of the produced output. When you are printing to a Rectangular area, you are effectively changing the ViewPort.

The ViewBox on the other hand is a trasformation of the svg content into the ViewPort. In most cases the ViewBox width and height will be equal to the svg's width and height. But this is not always the case. In SVG.ReadIn, the ViewBox width and height are initialized to the svg's ones before they are read from the file.

The scaling factors calculated in TSVG.SetBounds should be based on the ViewBox width and height and not the svg's width and height as in the code below:

procedure TSVG.SetBounds(const Bounds: TGPRectF);
begin
  FRootBounds := Bounds;

  if FWidth = 0 then
    FWidth := FRootBounds.Width;

  if FHeight = 0 then
    FHeight := FRootBounds.Height;

  if (FViewBox.Width > 0) and (FRootBounds.Width > 0) then
    FDX := FRootBounds.Width / FViewBox.Width;

  if (FViewBox.Height > 0) and (FRootBounds.Height > 0) then
    FDY := FRootBounds.Height / FViewBox.Height;

  CalculateMatrices(FViewBox.Top, FViewBox.Left, FDX, FDY);
end;

Test with
Back.zip

Official 2.0 release candidate also for GetIt

Jim McKeeth asks us to publish this library on GetIt.

We can use today to do the latest tests and verify the stability, then we can release the official 2.0 version.

I'm closing the issue #42, the discussion continues here...

@pyscripter can you write a little documentation to integrate wiki documentation on the use of SetGlobalSVGHandler?

thanks to all!

Make svg rendering engine replaceable

Currently it's tied to GDI+ which is not working too well with lots of svg images. Literally the first image I tried did not render correctly.

svgfail

Ideally there would an interface that can be implemented to wrapper different svg engines.

I really wanted to use this library, as working with png's at multiple sizes is just too much work, but it fails on too many of my images (mostly from axialis so I cannot share them for testing with).

TSvg Load/SaveToStream inefficient

The TSvg LoadFromStream, SaveToStream convert text to a TStringList and then load./save that. This is inefficient. Replace with the following:

procedure TSVG.LoadFromStream(Stream: TStream);
var
  Size: Integer;
  Buffer: TBytes;
begin
  Stream.Position := 0;
  Size := Stream.Size;
  SetLength(Buffer, Size);
  Stream.Read(Buffer, 0, Size);
  LoadFromText(TEncoding.UTF8.GetString(Buffer));
end;

procedure TSVG.SaveToStream(Stream: TStream);
var
  Buffer: TBytes;
begin
  Buffer := TEncoding.UTF8.GetBytes(FSource);
  Stream.WriteBuffer(Buffer, Length(Buffer));
end;

The above deals with #18

TSVGRadialGradient.ReadIn does not read the gradientTransform matrix

TSVGLinearGradient.ReadIn reads the gradientTransform matrix but TSVGRadialGradient.Readln does not.

Move:

var
  Matrix: TMatrix;

  FillChar(Matrix, SizeOf(Matrix), 0);
  LoadTransform(Node, 'gradientTransform', Matrix);
  PureMatrix := Matrix;

from TSVGLinearGradient.ReadIn to the common ancestor TSVGGradient.ReadIn

Test with the attached
Back4.zip

Scaling Problem

Hi,

there might be a scaling Problem with specific SVG's.
In my example theres some pixels missing at the bottom of the SVG.
Inside the button theres also 1px of cropping on the right side.
I attached a screenshot and the SVG file i used to reproduce this behavior.
I'm using Delphi 10.4 Sydney 32bit Windows VCL Application without HighRes Support.

ImageSvgScaling

phone.svg.zip

Icon Editor not keeping added icons

After building and installing the SVGIconImageList, I added the two components to a project. Then I tried to Add a new Icon. I browsed to the file and it looked like it added, as I saw the preview and could adjust the size. Clicking OK closed the window. And I tried to set a SVGIconImage component to that index "0". But nothing showed. And when I re-opened the editor, the image is gone.

I also tried opening the SVGIconItems and manually adding it. But I could add the new item, I was unable to paste the text in the SVGText box. It appears to only allow a very minimal amount of text and the was no way to bring up a larger window to enter or edit the text.

I even tried to add several of the sample Icons and was unsuccessful.

Style sheets are not processed well.

For example the following fails

    <svg width="120" height="120"  
        viewPort="0 0 120 120" version="1.1" 
        xmlns="http://www.w3.org/2000/svg">

            <style type="text/css" >
                <![CDATA[
                    rect.rectClass {
                        stroke: #000066;
                        fill:   #00cc00;
                    }
                    circle.circleClass {
                        stroke: #006600;
                        fill:   #cc0000;
                    }
                ]]>
            </style>

        <rect class="rectClass" x="10" y="10" width="100" height="100"/>
        <circle  class="circleClass"   cx="40" cy="50" r="26"/>
    </svg>

#40 fixes that

Quadratic Bezier Curves are not drawn correctly

Test with:

<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">

  <!-- to hide the path, it is usually wrapped in a <defs> element -->
  <!-- <defs> -->
  <path id="MyPath" fill="none" stroke="red"
        d="M10,90 Q90,90 90,45 Q90,10 50,10 Q10,10 10,40 Q10,70 45,70 Q70,70 75,50" />
  <!-- </defs> -->

  <text>
    <textPath href="#MyPath">
      Quick brown fox jumps over the lazy dog.
    </textPath>
  </text>

</svg>

Problem rendering some "embarcadero samples" icons

In past, all the icons present into folder "D:\ETHEA\GitHub_EtheaDev\SVGIconImageList\Demo\NewSydneyVectors" where rendered correctly.
Now RAD_SERVER_Product icon.svg and C++Builder project icon.svg is not rendered correctly.
I remember that I've fixed a problem of initialitazion of svg color from black to inherit... but I'm not sure...
@pyscripter , can you check this problem?

Coordinates in double (PaintTo methods)

In all drawing libraries GDI, GDI+, DirectX size and coordinates are either Integer (GDI) or Single (GDI+, DirectX). The use of Double in the PaintTo methods is unnecessary and inefficient (due to the conversions).

Please replace all Double with Single.

Wrong FixedColor rendering using PreferNativeSvgSupport

Tested with the Demo: some color are "similar", some color are not rendered properly: eg.
clMaroon (r=128,g=0,b=0) is rendered as Red
clRed (r=255,g=0,b=0) is rendered as Red
I don't know why... ;-)
The problem is present only in some colors...

Create virtual SVG ImageList and SVG ImageCollection

I really need this feature to be able to use this library, so I made a start on it. This will allow the handling of DPI changes on different forms that share the same list of images (as is common). Obviously the highdpi stuff is only in 10.3+ but it would still be useful, as we could do things like have multiple image lists, with different sizes using the same collection of svg's.

I'm mostly coding this in XE7 as that's the earliest I have installed, but of course when I get to it I'll test with 10.3 and 10.4 - I have a 2 monitor setup with different dpi's so easy to test.

I will open a draft pull request soon with the code for this.

So far I have done the following :

  • Extracted TSVGIconItem and TSVGIconItems to a separate unit.
  • Created a TSVGIconImageCollection class which will contain the TSVGIconItems
  • Created a TSVGIconVirtualImageList class which uses the TSVGIconImageCollection for the list of images, and does the drawing etc.

For the moment I'm just copying and pasting parts of TSVGIconImageList as needed, but I can see a lot of duplication, so might look to introduce a new base class for both TSVGIconImageList and TSVGIconVirtualImageList as there is a lot of code duplication - I'll do that once I have confirmed my code is going to work.

SVGIconImageList.dpk is missing files

The four files added in my last PR are missing from the SVGIconImageList.dpk.

SVGInterfaces in '..\..\Source\SVGInterfaces.pas',
 D2DSVGHandler in '..\..\Source\D2DSVGHandler.pas',
 PasSVGHandler in '..\..\Source\PasSVGHandler.pas',
 Winapi.D2DMissing in '..\..\Source\Winapi.D2DMissing.pas';

Render Bug

Hello.
When switching icons quickly, they overlap each other.

DP13m6VCRE

===

But this is not all, the same overlay occurs immediately upon application initialization (in my FMX application) on some icons.

image
(compiled app)

image
(app in IDE)

aA9NUATBny

This icons from: https://icons8.com/line-awesome (tasks, users, list, cog)

D10.3. Windows 10

Demo application doesn't scale properly

Thank you for writing this component; it looks like an interesting and useful component!

There's a problem, though...the Demo application doesn't scale properly. The TListView and TTreeView loses all its images when moved to a screen that uses a higher DPI (in my case, this high DPI monitor is 192 DPI).

I'm using it with Delphi 10.3 and HiDPISupport is defined.

I found that after a DPI change, it was necessary to call TSVGIconImageList.RecreateBitmaps( ) otherwise the images would be blank. I'd expect TSVGIconImageList.DPIChangedMessageHandler( ) should probably call the RecreateBitmaps( ) method after the size change has been completed.

LoadFromStream/SaveToStream encoding inconsistency

TSVG.LoadFromStream:

   SL.LoadFromStream(Stream, TEncoding.UTF8);

TSVG.SaveToStream

   SL.SaveToStream(Stream);

SaveToStream will use the default encoding which is ANSI on Windows. So sgv text is written as ansi and read as utf8.
To make consistent save as utf8 as well.

Empty svg properties cause exceptions

For example:

raises an exception when parsed.

Solution:
In SVGProperties change LoadString to:

procedure LoadString(const Node: IXMLNode; const S: string;
  var X: string);
var
  Attribute: IXMLNode;
  V: Variant;
begin
  Attribute := Node.AttributeNodes.FindNode(S);
  if Assigned(Attribute) then
  begin
    V := Attribute.nodeValue;
    if VarType(V) = varNull then
      X := ''
    else
      X := V;
  end;
end;

Editor not applying new images

When I add a couple of images through the image editor by clicking on the Add button the Apply button remains greyed out. If I click on the Ok button the new images are not saved. As a work-around, if I replace one on the images or drag and drop it to different place in the list of images the Apply button becomes clickable and changes are saved when I click on the Apply and Ok buttons

StoreAsText default value

UDataModule.dfm saved as text
StoreAsText False: UDataModule.dfm size 512 Kb Loading Time: 256ms
StoreAsText True: UDataModule.dfm size 314 Kb Loading Time: 125ms

UDataModule.dfm saved as binary
StoreAsText False: UDataModule.dfm size 228Kb Loading Time: 253ms
StoreAsText True: UDataModule.dfm size 230Kb Loading Time: 127ms

StoreAsText True loads much faster. When the form is saved as Text there is an extra conversion HexToBin.

So I am not sure what the benefit of StoreAsText is (extra complexity - could be removed as well as the associated code) and it appears to me that in any case True should be the default value of StoreAsText.

Rendering of some SVG images is incorrect

90% of my SVG icons are rendering correctly, but that last 10% is holding me back from being able to use the library. I've tried hard to debug the reason, but have been unsuccessful so far. I have examples attached and show rendering by DevExpress and SVGIconImageList. Correcting the anomalies will make this library a must have in today's high res world.
SVGExamples.zip

Transform matrix is wrongly parsed

In SVGParse.pas GetMatrix is defined as follows:

function GetMatrix(const S: string): TMatrix;
var
  SL: TStrings;
begin
  Result := TMatrix.Identity;
  SL := GetValues(S, ',');
  try
    if SL.Count = 6 then
    begin
      Result.m11 := StrToTFloat(SL[0]);
      Result.m12 := StrToTFloat(SL[1]);
      Result.m21 := StrToTFloat(SL[2]);
      Result.m22 := StrToTFloat(SL[3]);
      Result.m31 := StrToTFloat(SL[4]);
      Result.m32 := StrToTFloat(SL[5]);
    end;
  finally
    SL.Free;
  end;
end;

This is wrong. The i, j indices shoud be reversed:

function GetMatrix(const S: string): TMatrix;
var
  SL: TStrings;
begin
  Result := TMatrix.Identity;
  SL := GetValues(S, ',');
  try
    if SL.Count = 6 then
    begin
      Result.m11 := StrToTFloat(SL[0]);
      Result.m21 := StrToTFloat(SL[1]);
      Result.m12 := StrToTFloat(SL[2]);
      Result.m22 := StrToTFloat(SL[3]);
      Result.m13 := StrToTFloat(SL[4]);
      Result.m23 := StrToTFloat(SL[5]);
    end;
  finally
    SL.Free;
  end;
end;

See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform and test with

Back3.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.