Bug 162309 - Wrong page and shape sizes when importing SVG
Summary: Wrong page and shape sizes when importing SVG
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Draw (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: filter:svg
Depends on:
Blocks: SVG-filters
  Show dependency treegraph
 
Reported: 2024-08-02 07:12 UTC by Mike Kaganski
Modified: 2024-08-06 14:51 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
A rectangle 1 by 2 mm (197 bytes, image/svg+xml)
2024-08-02 07:12 UTC, Mike Kaganski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2024-08-02 07:12:23 UTC
Created attachment 195658 [details]
A rectangle 1 by 2 mm

The attachment is as simple as:

<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.2" width="1mm" height="2mm" viewBox="0 0 1 2" xmlns="http://www.w3.org/2000/svg">
 <g>
  <rect x="0" y="0" width="1" height="2"/>
 </g>
</svg>

It is a file with viewBox of 1x2 from [0, 0]; the user units of mm; and a single rectangle 1x2 from [0, 0] (so covering 100% of the viewBox).

It is expected, that importing this, Draw would use the document information to construct its document model (as always should be done with any document we import: we take page size from DOCX, XLS, ... - whenever that info is there). Here, the document dictates the page size clearly - it must be 1 x 2 mm; and the rectangle on it must be 1 x 2 mm, positioned at point [0, 0].

In reality, the page is 1.26 x 2.26 mm; the rectangle is 0.98 x 1.98 mm (which is intolerable in this specific case, where both SVG uses mm, and Draw's internal units are mm/100, so must result in exact whole numbers); and the position of the rectangle is [0.06 mm, 0.06 mm].

This is not just a curious non-issue. Take any SVG having a clear definition of their box; and convert-to a raster image. The end result will always have one too many pixels on X and Y, and the object boundaries aligned to SVG units will all be in the middle of resulting pixels, creating blurry edges. Doing this with this attachment would not create a proper totally black image with proportions 1 : 2, but a 5x9 bitmap with unexpected white and grey borders.
Comment 1 m_a_riosv 2024-08-02 23:14:36 UTC
Reproducible with
Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 3ee53d75d253fb7fe2eb8db44afca95fda7f156d
CPU threads: 16; OS: Windows 11 X86_64 (10.0 build 22631); UI render: Skia/Raster; VCL: win
Locale: es-ES (es_ES); UI: en-US
Calc: CL threaded

But with a little different size, 1.25x2.25.
Seems as the borders were added to the size.
Drawing a rectangle over the black box, has a 1x2 size.