Home
Categories
Dictionary
Download
Project Details
FAQ
License

Units support



The library support the following length and position units[1] :
  • The px, pt, in, cm, mm, em, and ex units
  • The % unit

Behavior for the non relative units

  • The computation for the ex unit is an approximation, considering one 1/2 of the em unit
  • The computation for the em unit does not take into account for the moment the height of the fonts

Size Type

Main Article: LoaderParameters

The sizeType parameter of the LoaderParameters specifies how sizes and dimensions which are not defined in pixels will be managed by the loader:

Example

Consider the following SVG file:
   <svg width="210mm" height="297mm" viewBox="0 0 5cm 5cm">
      <g id="layer1">
         <circle fill="red" cx="2cm" cy="2cm" r="2cm" />
      </g>
   </svg>
If we define:
   SVGImage img = SVGLoader.load(<my SVG file>);
By default the radius of the circle will be 2 centimeters, considering the dpi as 96 pixels per inch.

If we define:
   LoaderParameters params = new LoaderParameters();
   params.sizeType = SizeType.FORCED_DPI;
   params.dpi = 76;
   SVGImage img = SVGLoader.load(<my SVG file>, params);
Then the radius of the circle will be 2 centimeters, considering the dpi as 76 pixels per inch.

Behavior for the % unit

The "%" unit specifies a length or a position relative to the viewport. The library works in the following way:
  • If the with and height attributes are present in the SVG root, they are used to specify the dimensions of the viewport
  • Else if the viewBox attribute is present, it will be used to get the width and height of the viewport

Limitations

The path element does not currently support the "%" unit.

Notes


Categories: Fromsvgsupport

Copyright 2021-2022 Herve Girod. All Rights Reserved. Documentation and source under the BSD-3-Clause License