|
35 | 35 | // Attachments use "t" and "b" instead of "top" and "bottom" since v0.3.0.
|
36 | 36 | #let using-typst-v030-or-later = using-typst-v080-or-later or $a^b$.body.has("t")
|
37 | 37 |
|
| 38 | +#let using-typst-v090 = using-typst-v080-or-later and str(-1).codepoints().first() == "\u{2212}" |
| 39 | +#let using-typst-v0110 = using-typst-v090 and sys.version >= version(0, 11, 0) |
| 40 | + |
| 41 | +// Polyfill for locate() when there is no context yet |
| 42 | +#let _locate = if using-typst-v0110 { func => context(func(here())) } else { locate } |
| 43 | + |
| 44 | +// Polyfill for locate() when there is already context |
| 45 | +#let _locate_inherit = if using-typst-v0110 { func => func(here()) } else { locate } |
| 46 | + |
| 47 | +// Polyfill for style() when there is already context |
| 48 | +#let _style_inherit = if using-typst-v0110 { func => func((:)) } else { style } |
| 49 | + |
| 50 | +// Polyfill for measure(_, styles) |
| 51 | +#let _measure = if using-typst-v0110 { (value, _) => measure(value) } else { measure } |
| 52 | + |
38 | 53 | // This is true if types have fields in the current Typst version.
|
39 | 54 | // This means we can use stroke.thickness, length.em, and so on.
|
40 | 55 | #let typst-fields-supported = using-typst-v080-or-later
|
|
443 | 458 | let em = len.em
|
444 | 459 | // Measure with abs (and later multiply by the sign) so negative em works.
|
445 | 460 | // Otherwise it would return 0pt, and we would need to measure again with abs.
|
446 |
| - let measured-em = calc-sign(em) * measure(box(width: calc.abs(em) * 1em), styles).width |
| 461 | + let measured-em = calc-sign(em) * _measure(box(width: calc.abs(em) * 1em), styles).width |
447 | 462 |
|
448 | 463 | return pt + measured-em
|
449 | 464 | }
|
450 | 465 |
|
451 | 466 | // Fields not supported, so we have to measure twice when em can be negative.
|
452 |
| - let measured-pt = measure(box(width: len), styles).width |
| 467 | + let measured-pt = _measure(box(width: len), styles).width |
453 | 468 |
|
454 | 469 | // If the measured length is positive, `len` must have overall been positive.
|
455 | 470 | // There's nothing else to be done, so return the measured length.
|
|
462 | 477 | // Hence, `len` must either be `0pt` or negative.
|
463 | 478 | // We multiply `len` by -1 to get a positive length, draw a line and measure it, then negate
|
464 | 479 | // the measured length. This nicely handles the `0pt` case as well.
|
465 |
| - measured-pt = -measure(box(width: -len), styles).width |
| 480 | + measured-pt = -_measure(box(width: -len), styles).width |
466 | 481 | return measured-pt
|
467 | 482 | }
|
468 | 483 |
|
|
476 | 491 | return len
|
477 | 492 | }
|
478 | 493 |
|
479 |
| - // At this point, we will need to draw a line for measurement, |
480 |
| - // so we need the styles. |
481 |
| - if styles == none { |
482 |
| - panic("Cannot convert length to pt ('styles' not specified).") |
483 |
| - } |
484 |
| - |
485 | 494 | return measure-pt(len, styles)
|
486 | 495 | }
|
487 | 496 |
|
|
543 | 552 | return convert-ratio-type-to-pt(len.ratio, page-size) + convert-length-type-to-pt(len.length, styles: styles)
|
544 | 553 | }
|
545 | 554 |
|
546 |
| - // We will need to draw a line for measurement later, |
547 |
| - // so we need the styles. |
548 |
| - if styles == none { |
549 |
| - panic("Cannot convert relative length to pt ('styles' not specified).") |
550 |
| - } |
551 |
| - |
552 | 555 | // Note on precision: the `repr` for em components is precise, unlike
|
553 | 556 | // other length components, which are rounded to a precision of 2.
|
554 | 557 | // This is true up to Typst 0.9.0 and possibly later versions.
|
|
1258 | 1261 |
|
1259 | 1262 | // calculate the size of auto columns (based on the max width of their cells)
|
1260 | 1263 | #let determine-auto-columns(grid: (), styles: none, columns: none, inset: none, align: auto, fit-spans: none, page-width: 0pt) = {
|
1261 |
| - assert(styles != none, message: "Cannot measure auto columns without styles") |
1262 | 1264 | let total_auto_size = 0pt
|
1263 | 1265 | let auto_sizes = ()
|
1264 | 1266 | let new_columns = columns
|
|
1319 | 1321 | inset: cell_inset, align_default: auto
|
1320 | 1322 | )
|
1321 | 1323 |
|
1322 |
| - let width = measure(cell-box, styles).width// + 2*cell_inset // the box already considers inset |
| 1324 | + let width = _measure(cell-box, styles).width// + 2*cell_inset // the box already considers inset |
1323 | 1325 |
|
1324 | 1326 | // here, we are excluding from the width of this cell
|
1325 | 1327 | // at this column all width that was already covered by
|
|
1498 | 1500 |
|
1499 | 1501 | // calculate the size of auto rows (based on the max height of their cells)
|
1500 | 1502 | #let determine-auto-rows(grid: (), styles: none, columns: none, rows: none, align: auto, inset: none, fit-spans: none) = {
|
1501 |
| - assert(styles != none, message: "Cannot measure auto rows without styles") |
1502 | 1503 | let total_auto_size = 0pt
|
1503 | 1504 | let auto_sizes = ()
|
1504 | 1505 | let new_rows = rows
|
|
1543 | 1544 | // measure the cell's actual height,
|
1544 | 1545 | // with its calculated width
|
1545 | 1546 | // and with other constraints
|
1546 |
| - let height = measure(cell-box, styles).height// + 2*cell_inset (box already considers inset) |
| 1547 | + let height = _measure(cell-box, styles).height// + 2*cell_inset (box already considers inset) |
1547 | 1548 |
|
1548 | 1549 | // here, we are excluding from the height of this cell
|
1549 | 1550 | // at this row all height that was already covered by
|
|
2027 | 2028 | // NOTE: This function cannot differentiate between the actual page
|
2028 | 2029 | // and a possible box or block where the component using this function
|
2029 | 2030 | // could be contained in.
|
2030 |
| -#let get-page-dim-writer() = locate(w_loc => { |
| 2031 | +#let get-page-dim-writer() = _locate(w_loc => { |
2031 | 2032 | let table_id = _tablex-table-counter.at(w_loc)
|
2032 | 2033 | let page_dim_state = get-page-dim-state(table_id)
|
2033 | 2034 |
|
2034 |
| - place(top + left, locate(loc => { |
| 2035 | + place(top + left, _locate(loc => { |
2035 | 2036 | page_dim_state.update(s => {
|
2036 | 2037 | if s.top_left != none {
|
2037 | 2038 | s
|
|
2044 | 2045 | })
|
2045 | 2046 | }))
|
2046 | 2047 |
|
2047 |
| - place(bottom + right, locate(loc => { |
| 2048 | + place(bottom + right, _locate(loc => { |
2048 | 2049 | page_dim_state.update(s => {
|
2049 | 2050 | if s.bottom_right != none {
|
2050 | 2051 | s
|
|
2088 | 2089 | let vlines = row-group.vlines
|
2089 | 2090 | let (start-y, end-y) = row-group.y_span
|
2090 | 2091 |
|
2091 |
| - locate(loc => { |
| 2092 | + _locate(loc => { |
2092 | 2093 | // let old_page = latest-page-state.at(loc)
|
2093 | 2094 | // let this_page = loc.page()
|
2094 | 2095 |
|
|
2114 | 2115 | if repeat-header != false {
|
2115 | 2116 | header-pages-state.update(l => l + (page,))
|
2116 | 2117 | if (repeat-header == true) or (type(repeat-header) == _int-type and rel_page <= repeat-header) or (type(repeat-header) == _array-type and rel_page in repeat-header) {
|
2117 |
| - let measures = measure(first-row-group.content, styles) |
| 2118 | + let measures = _measure(first-row-group.content, styles) |
2118 | 2119 | place(top+left, first-row-group.content) // add header
|
2119 | 2120 | added_header_height = measures.height
|
2120 | 2121 | }
|
|
2163 | 2164 | dy: height-between(start: first_y, end: y) + added_header_height,
|
2164 | 2165 | cell_box.box)
|
2165 | 2166 |
|
2166 |
| - // let box_h = measure(cell_box.box, styles).height |
| 2167 | + // let box_h = _measure(cell_box.box, styles).height |
2167 | 2168 | // tallest_box_h = calc.max(tallest_box_h, box_h)
|
2168 | 2169 | }
|
2169 | 2170 | first_row = false
|
|
2838 | 2839 | let map-cols = validate-map-func(map-cols)
|
2839 | 2840 | let fit-spans = validate-fit-spans(fit-spans, default: (x: false, y: false))
|
2840 | 2841 |
|
2841 |
| - layout(size => locate(t_loc => style(styles => { |
| 2842 | + layout(size => _locate_inherit(t_loc => _style_inherit(styles => { |
2842 | 2843 | let table_id = _tablex-table-counter.at(t_loc)
|
2843 | 2844 | let page_dimensions = get-page-dim-state(table_id)
|
2844 |
| - let page_dim_at = page_dimensions.final(t_loc) |
| 2845 | + let page_dim_at = if using-typst-v0110 { page_dimensions.final() } else { page_dimensions.final(t_loc) } |
2845 | 2846 | let t_pos = t_loc.position()
|
2846 | 2847 |
|
2847 | 2848 | // Subtract the max width/height from current width/height to disregard margin/etc.
|
|
0 commit comments