JFLib

diagram_core/src/ops/picture.rs#

Source: lib/diagram_core/src/ops/picture.rs

ops::picture -- a picture file as a shape (RE-02 "Bild aus Datei", SP-09): its format, size
and resolution read from its header, its bytes as a media part of the package, a Foreign
shape that shows it

  probe_picture(bytes) -> Option<PictureInfo>   PNG (IHDR, pHYs), JPEG (SOFn, JFIF density),
                                      GIF (logical screen), BMP (DIB header, pixels per metre):
                                      format, pixels, dots per inch (0: the file does not say)
  info.size(per_inch, max) -> [w, h]  the size Visio gives it: pixels / dpi (96 when the file
                                      does not say) in paper inches, times the drawing units
                                      per paper inch, scaled down (proportionally) into `max`
  new_picture(tx, eng, owner, bytes, format, centre, size) -> ShapeRef

How Visio keeps a picture ([MS-VSDX] ForeignData, Foreign shapes): a shape of Type
"Foreign" with a ForeignData element (ForeignType="Bitmap", CompressionType "PNG", "JPEG",
"GIF" ...) whose Rel names a part of the package by an image relationship
(/visio/media/imageN.ext; diagram_io::vsdx::write makes the relationship and the content type
from Document::parts, the shape refers to the part by its name).  The picture fills the box
ImgOffsetX/Y, ImgWidth/ImgHeight inside the shape, cut at the shape's box; Visio writes them
as ImgOffsetX = ImgWidth*0, ImgOffsetY = ImgHeight*0, ImgWidth = Width*1, ImgHeight =
Height*1, so the picture stretches with the shape.  The shape here also has a rectangle in
Geometry (no fill) and LinePattern 0, so a border can be given later (Line format) without a
line at first; Annahme: Visio's inserted pictures carry such a section too, their border is
off until set.  A BMP is best converted to PNG by the caller (CompressionType "BMP" is
written for it here, Annahme from [MS-VSDX]'s list of compression types).
  • enum PictureFormat the formats of picture files
    • Png
    • Jpeg
    • Gif
    • Bmp

impl PictureFormat

  • fn extension(self) -> &'static str the part name's extension

  • fn content_type(self) -> &'static str the part's content type

  • fn compression(self) -> &'static str ForeignData's CompressionType

  • struct PictureInfo what a picture file's header says

    • format: PictureFormat
    • w: u32 -- pixels
    • h: u32
    • dpi: [f64; 2] -- dots per inch across and down (0: the file does not say)

impl PictureInfo

  • fn size(&self, per_inch: f64, max: [f64; 2]) -> [f64; 2] the size of the picture's shape: its pixels at its resolution (96 dpi when the file does not say) in paper inches times per_inch (drawing units per paper inch), scaled down into max (width, height; 0: no bound) keeping its proportions

  • fn probe_picture(b: &[u8]) -> Option<PictureInfo> the format, pixels and resolution of a picture file (None: no PNG, JPEG, GIF or BMP, or a header that ends too soon or names no pixels)

  • fn new_picture(tx: &mut Transaction, eng: &mut Engine, owner: Owner, bytes: &[u8], format: PictureFormat, centre: [f64; 2], size: [f64; 2]) -> Result<ShapeRef, EditError> a picture of format with these bytes as a Foreign shape of size (drawing units) around centre on top of the owner's shapes; the bytes become a new media part -> the shape (an empty size or no bytes: Invalid)

Source: docs/API.md in the JFLib repository.