JFLib

diagram_core/src/pagesetup.rs#

Source: lib/diagram_core/src/pagesetup.rs

pagesetup -- a page's size against its drawing and its printer paper (PG-04, PG-05, RW-01 ..
RW-03): orientation, a size of the menu, the page fitted to its drawing, automatic size in
tiles of the printed sheet

  size(doc, page) -> [w, h]              PageWidth, PageHeight (drawing units, inches)
  scale(doc, page)                       paper inches per drawing inch (PageScale / DrawingScale)
  landscape(doc, page)                   the page is wider than high
  set_orientation(tx, eng, page, landscape)   Hochformat / Querformat: width and height
                                         swapped when the page lies the other way,
                                         PrintPageOrientation 1 / 2
  set_paper_size(tx, eng, page, [w, h])  the page to w x h paper inches in its orientation
  auto_size(doc, page) / set_auto_size(tx, page, on)   Automatisch anpassen
  content(doc, page) -> Option<[x0, y0, x1, y1]>   the box of the page's top-level shapes
  fit_to_drawing(tx, eng, page, margins) the page around its drawing, the shapes moved in
  Tiles::new(paper, margins, zoom); grow(tx, eng, page, &tiles)   automatic size after a
                                         gesture: whole tiles added or taken away
  shift(tx, eng, page, d)                (JD21) the drawing moved with the page's origin,
                                         dynamically glued connector ends along

The cells (Visio's ShapeSheet reference, Page Properties and Print Properties sections):
* DrawingSizeType: 0 same as printer (visPrintSetup), 1 fit page to drawing contents
  (visTight), 2 standard (visStandard), 3 custom page size (visCustom), 4 custom scaled, 5
  metric (ISO), 6 ANSI engineering, 7 ANSI architectural.
* DrawingResizeType: 0 the page resizes automatically when DrawingSizeType is 0, else not;
  1 the page resizes automatically; 2 it does not.  set_auto_size writes 1 or 2.
* PrintPageOrientation: 0 same as printer, 1 portrait, 2 landscape.
A size chosen from the menu or fitted to the drawing turns the automatic size off: the Page
Size register of Visio's Page Setup offers "let Visio expand the page" and a fixed size as
alternatives (Visio 2016 Step by Step, chapter 3).  Assumption, not checked in Visio: fitting
to the drawing turns it off as well (DrawingResizeType 2), so the next gesture does not cut
the fitted page back into tiles.

Automatic size (Step by Step, chapter 3: "Auto Size works both horizontally and vertically",
the extended page goes again when its last shape leaves it): a tile is the printed sheet,
the first one the whole paper, each further one the paper less the margins left and right
(top and bottom) -- a page of the local corpus agrees: A4 landscape with 0.25 in margins and
two by two tiles is 2 x 11.69 - 0.5 = 22.89 in wide and 2 x 8.27 - 0.5 = 16.04 in high.  After a
gesture the page gains a tile on each side where a shape juts out and loses an empty tile at
an edge, never below the first one; a page that grows to the left or down moves its drawing
(the origin stays at the bottom left corner, as every coordinate of the file says).  Nothing
happens on opening a file (PLAN.md, "Fallen"): only the app's gesture asks.
  • fn size(doc: &Document, page: PageRef) -> [f64; 2] PageWidth and PageHeight in drawing units (inches; Visio's 8.5 x 11 in when missing)

  • fn scale(doc: &Document, page: PageRef) -> f64 paper inches per drawing inch: PageScale / DrawingScale (1 without a scale)

  • fn landscape(doc: &Document, page: PageRef) -> bool whether the page lies landscape (wider than high)

  • fn set_orientation(tx: &mut Transaction, eng: &mut Engine, page: PageRef, landscape: bool) -> Result<bool, EditError> Hochformat (landscape = false) / Querformat: width and height swapped when the page lies the other way, PrintPageOrientation 1 or 2, then what depends on the page computed again -> whether anything changed

  • fn set_paper_size(tx: &mut Transaction, eng: &mut Engine, page: PageRef, paper: [f64; 2]) -> Result<bool, EditError> a size of the menu (paper inches, portrait or landscape alike): the page gets it in its own orientation (DrawingSizeType 2, standard; the automatic size goes off) -> changed

  • fn auto_size(doc: &Document, page: PageRef) -> bool whether the page grows and shrinks with its drawing (Automatisch anpassen): DrawingResizeType 1, or 0 with DrawingSizeType 0

  • fn set_auto_size(tx: &mut Transaction, page: PageRef, on: bool) -> Result<bool, EditError> turn the automatic size on (DrawingResizeType 1) or off (2) -> changed

  • fn content(doc: &Document, page: PageRef) -> Option<[f64; 4]> the box of the page's top-level shapes on the page (drawing units, y up; guides and deleted shapes left out); None for a page without shapes

  • fn fit_to_drawing(tx: &mut Transaction, eng: &mut Engine, page: PageRef, margins: [f64; 4]) -> Result<bool, EditError> the page around its drawing (Größe an Zeichnung anpassen): the box of its shapes and margins (left, top, right, bottom; paper inches) around it, the shapes moved so that the box starts at the left and bottom margin; DrawingSizeType 1 (fit page to drawing contents), the automatic size off -> changed (false for a page without shapes)

  • struct Tiles the tiles of the automatic size on paper (inches): the first tile, each further one

    • base: [f64; 2] -- the first tile: the paper (over the print zoom)
    • step: [f64; 2] -- each further tile: the paper less the margins (over the print zoom)

impl Tiles

  • fn new(paper: [f64; 2], margins: [f64; 4], zoom: f64) -> Tiles the tiles of a sheet of paper (width, height; inches, in the page's print orientation) with margins (left, top, right, bottom) printed at zoom (1 = 100 %)

  • fn grow(tx: &mut Transaction, eng: &mut Engine, page: PageRef, tiles: &Tiles) -> Result<Option<[f64; 2]>, EditError> the automatic size after a gesture (see the file header): the page gains or loses whole tiles where its drawing juts out or left empty space, the drawing moves by what the page grew or shrank at its left and bottom edge -> that move (drawing units) when the page changed, None when it stays (the automatic size is off, it fits, a step is too small)

  • fn shift(tx: &mut Transaction, eng: &mut Engine, page: PageRef, d: [f64; 2]) -> Result<(), EditError> (JD21) every top-level shape of the page moved by d (ops::shift_all: the page's origin moves under the drawing), and the ends of 1-D shapes glued to a whole shape along: their _WALKGLUE has no value of the engine's, so the stored point moves by d too (the formula stays); static glue follows its formula by itself. Before, a page that grew to the left or down left such connectors behind

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