Skip to content

Designer Engine

Pablo Martínez López edited this page Nov 28, 2026 · 21 revisions

Designer Engine

English · Español

The designer engine is the part of proxy-core::design that turns one effective design into pixels: the data model, the effective-design resolver and render hash, text shaping with parley, glyph painting with tiny-skia, symbols, and the per-face painter in render.rs. Multi-piece cards (split, flip, meld…) are assembled on top of it and covered in Designer-Composition.

For concepts (CardDesign, Collection, card > collection > factory) read Designer-Overview first.

Public surface

Crate path: src-tauri/crates/proxy-core/src/design/.

Item Where Meaning
effective(d, collection) -> EffectiveDesign effective.rs Resolve card > collection > factory. On cards with two printed faces (printed_faces > 1), each face with FaceDesign.settings also gets its own EffectiveDesign in faces[i]: CardDesign::for_face(i) puts the face's FaceSettings (style, pack style and variant, frame, emblem, options) in place of the card's and resolves it the same way, so each field still falls back to the collection and the factory. EffectiveDesign::for_face(i) returns it (or the card's own). render and render_overlay call it right after clamping face; fingerprint hashes only that face's effective design (the other faces' settings are left out, so changing one does not repaint the other, and designs without own settings keep their old fingerprints: both fields are skipped when empty). The app (paint.rs) also takes the pack from for_face(face).frame.pack. Composed layouts (split, aftermath, flip…) are one printed face and ignore it.
fingerprint(e, lang, face, resources) -> String effective.rs SHA-256 hex render key.
Engine::factory_default() render.rs Per-thread typesetting state: Fonts (fonts) plus a Typesetter. Loads the built-in fonts.
Resources { pack, symbols, images } render.rs What a render borrows: the frame Pack, the Symbols, and an ImageSource provider.
trait ImageSource { fn image(&self, blob) -> Option<Arc<RgbaImage>> } render.rs The core never reads disk; the caller supplies decoded images. NoImages is the empty implementation.
render(engine, e, face, lang, assets, card, width_px, output) -> Result<Render, DesignError> compose.rs (re-exported from render.rs) Paint one printed face. Render { image: RgbaImage, warnings: Vec<DesignWarning> }.
render_overlay(...) -> Option<OverlayLayer> compose.rs The card without its artwork, on transparency, plus where the artwork goes. For live artwork dragging.
RenderTarget::{Screen, Print} render.rs Screen: rounded transparent corners. Print: opaque, square corners (the cutter rounds them; bleed repeats the edge).
shrunk(img, side) render.rs Downscale an artwork to at most side px on the long side (the image the live preview moves).
Fonts::{new, load, load_emoji, set_fallbacks, load_cjk, has, has_writing_system} fonts.rs Font catalogue; load_emoji registers the colour emoji font as the generic emoji family; set_fallbacks and load_cjk register per-script fallbacks (see below).
engine_texts, language_types engine_texts.rs, language_types.rs Fixed words the engine paints and offline type lines, per design language (see Design languages).
Symbols, CustomSymbols symbols.rs Scryfall symbol SVGs and pack-own symbols.

Dependencies (src-tauri/crates/proxy-core/Cargo.toml): parley (layout/shaping), skrifa (glyph outlines), tiny-skia (rasteriser), resvg (SVG: frames and symbols), fast_image_resize (Lanczos3 and pixel resizing), image, regex, sha2.

Pipeline at a glance

flowchart TD
  A["effective(): EffectiveDesign"] --> B["compose::render: pick CardLayout + Body"]
  B --> C["paint_face (render.rs): one face on a Canvas"]
  C --> C1["colour choice: frame_colors + Tones + vars"]
  C1 --> C2["fit rules text: bodies::fit, dynamic box"]
  C2 --> C3["background layers, artwork, window_svg"]
  C3 --> C4["pack layers: layers with when conditions"]
  C4 --> C5["texts: cost, title, type, label, emblem, rules, P/T, footer"]
  C5 --> D["corner mask, from_pixmap: RgbaImage + warnings"]
Loading

model.rs: the contract

See Designer-Overview for the type table. Engine-relevant details:

  • FineTuning::clamped() clamps everything: offsets to +-MAX_NUDGE_MM (3 mm); rules_box_opacity to 0..1; art_radius 0..20 mm; card_radius 0..6 mm; art_fade 0..MAX_FADE_MM (25 mm); art_fade_extension 0..MAX_FADE_EXTENSION_MM (35 mm); rules_box_height +-MAX_BOX_HEIGHT_MM (10 mm); text sizes (and cost_size, the mana symbols, which share the range) to MIN_TEXT_SCALE..MAX_TEXT_SCALE (0.5..1.6); line spacing to MIN_LINE_SPACING..MAX_LINE_SPACING (0.7..1.6). effective always applies it.
  • Title squeeze constants: DEFAULT_SQUEEZE_MIN 0.65, range SQUEEZE_MIN_FLOOR 0.55 to SQUEEZE_MIN_CEILING 0.75, DEFAULT_SQUEEZE_BASE 1.0.
  • DesignWarning variants: NoOfficialText, TextDoesNotFit { slot, excess }, TitleShrunk { slot }, RulesEdited, MissingName, FontNotFound, MissingSymbols, PackWithoutLayout, StyleNotInPack, UnknownLayout, CollectionLost, NoRibbon, MissingFonts { lang }.
  • Per-language values (DesignLang, ByLang<T>, FaceData.printed_names, CardData.textless) are described in Design languages.
  • Serialised names are English since 4.1.2. The names 4.1 wrote are still read through serde aliases (estiloPack, variantePack, ajustes, sinTexto, textoNoCabe…), and the footer symbols {PINCEL} and {ESTRELLA} still draw (symbols.rs → house).
  • Tests: model.rs round-trips a two-face design, checks the 108-card deck stays under 2 MB of JSON (size_of_a_designed_deck), checks that a pre-2.0 DeckCard JSON still parses without a design key (a_1x_card_reads_the_same_and_writes_no_design), and the language compatibility tests listed below.

draft.rs (core): text before painting

Not to be confused with src-tauri/src/design/draft.rs (the app-side Scryfall-to-CardData builder, see Designer-App-Layer). The core one is pure text logic:

  • effective_rules(d, face, lang): the rules text that is painted. A hand-written rules_override wins, but the original card name is still replaced by the thematic one.
  • substitute_name(text, originals, own, spanish): replaces the original names (full names first, longest first, then their short forms such as the part before the comma) by the thematic name. Whole words only (replace_word). It uses private-use marker characters so an already-substituted name is never replaced twice. In Spanish, drop_articles drops the article before the substituted name (del becomes de, al becomes a, el/la/los/las removed) because the thematic name is usually a character name, not an object.
  • effective_rules looks for the original names to replace in the face name, every face name and the name printed in that language (FaceData::printed_name(lang)); the Spanish article rule only applies to DesignLang::Es.
  • effective_name: thematic name of that language (FaceDesign::texts(lang)), else the printed name in that language (FaceData::printed_name(lang)), else the English name. original_name_of: all face names joined with //.
  • spanish_type_line(en) (Spanish grammar) and translated_type_line(en, lang) (language_types::type_line_in first, which also covers Spanish, then the Spanish grammar; None in English or when the types are unknown) build a type line without network. A subtype nobody knows stays in English («Creature — Eldrazi» becomes «Criatura — Eldrazi»), because an almost-translated line is better than one entirely in English. fix_types only writes a line that differs from the English one. fix_types(card, lang) fills the type of faces that still carry the English one (designs saved before the translation was known); fix_spanish_types is the Spanish shortcut.
  • next_number / number: footer numbering, 0001... for cards and T001... for tokens, above the highest already in the deck.

fonts.rs: fonts without the system

Fonts wraps a parley::FontContext built with CollectionOptions { shared: false, system_fonts: false }. Only fonts passed to load(Vec<u8>) (TTF/OTF, variable fonts included) exist. Rationale: a card must look the same on every machine, and a missing system font must never silently change layout.

  • Built-in fonts (FACTORY_FONTS in render.rs, via include_bytes! from assets/fonts/): Spectral Regular/Italic/SemiBold/Bold and Montserrat (variable). Their licences are alongside (Spectral-LICENSE.txt, Montserrat-LICENSE.txt).
  • Emoji font (EMOJI_FONT in render.rs): Noto Color Emoji in COLRv1 (assets/fonts/Noto-COLRv1.ttf, the 2D/fonts/Noto-COLRv1.ttf file of googlefonts/noto-emoji at a fixed commit whose SHA-256 is noted next to the constant, about 5 MB; OFL 1.1, licence in Noto-COLRv1-LICENSE.txt). Engine::factory_default loads it with Fonts::load_emoji, which sets it as GenericFamily::Emoji. parley already asks for that family whenever a cluster is an emoji (ZWJ sequences, skin tones, flags, U+FE0F), after the text family, so no text font needs to carry emoji and a card never shows an empty box for them. It is bundled (not downloaded) because emoji can appear in any text of any card. Caladea is in assets/fonts/ only as a test fixture (fonts.rs and resources.rs tests).
  • Latin and Cyrillic fallback. Engine::factory_default calls Fonts::set_fallbacks(&["Spectral", "Montserrat"]), which appends those families as fontique fallbacks for the Latn and Cyrl scripts. A pack or imported font that lacks «ș», «ł» or the Cyrillic alphabet takes only those characters from the house fonts instead of painting boxes; characters the requested font has are untouched. The house fonts cover the Latin of every app language and Russian/Ukrainian Cyrillic.
  • CJK fonts. Japanese, Korean and Chinese need fonts that are too big to bundle (Noto Sans JP/KR/SC/TC, downloaded by the app; see Designer-App-Layer). Fonts::load_cjk(data, writing_system) registers one as a fallback for its scripts both with its language (ja, ko, zh-Hans, zh-Hant) and without one, so the same ideograph gets the Japanese or the Chinese form depending on the text's locale, and a stray ideograph in a Latin-script card still has a font. has_writing_system(e) is always true for WritingSystem::Latin/Cyrillic and true for a CJK script once its font is loaded; the painter raises DesignWarning::MissingFonts { lang } when it is false.
  • Imported and downloaded fonts are loaded by the app into every thread's Engine (DesignResources::with_engine in src-tauri/src/design/resources.rs, rebuilt when the font "generation" counter changes). Font ids are the SHA-256 of the file. See Frame-Packs for the downloadable OFL catalogue.
  • A collection can ask for another title/rules family (font_title, font_rules) and weights (Weights). If it is not loaded, DrawnCard::font_without_weight falls back to the pack's font and records DesignWarning::FontNotFound.
  • Those choices were made for the collection's pack. When the card has its own frame with a different pack (EffectiveDesign::other_pack, written only when true so older fingerprints do not change), DrawnCard::font ignores them for every role whose pack font is not the house one (has_own_font: Spectral for the texts, Montserrat for the footer). A Balatro card in a collection set up for the Original frames therefore uses the pack's pixel font, while builtin ↔ Original keeps the collection's fonts, since both packs use the house fonts.

text.rs: rich text and layout

  1. Parsing to Paragraphs (Vec<Fragment>, Fragment::Text { text, italic } or Fragment::Symbol):
    • rules(text): one paragraph per line. Text inside parentheses is italic (reminder text); {X} becomes a symbol; [[word]] marks a highlight span; the short "ability word" before — at the start of a line (at most 4 words, no { : ( . , •) becomes italic and coloured (ability_word).
    • flavor(text): flavour text, all italic.
    • with_symbols(text): symbols only (type line, footer). plain(text): plain.
    • Highlight and ability-word spans use private-use markers (HIGHLIGHT, ABILITY), stripped in typeset and painted in the pack's textColors colours if the pack has them; otherwise the markers vanish and the text is the normal colour.
  2. Typesetter::typeset(fonts, paragraph, style, width) lays one paragraph out with parley: default family/size/weight/line height, forced lining numerals ("lnum", plus "smcp" for small caps), italics as ranges, colour spans, then break_all_lines(width) and align. width = None means a single line.
    • Symbols are inline boxes of side style.size * SYMBOL_SIDE (0.80), gap SYMBOL_GAP (0.05), dropped SYMBOL_DROP (0.09) below the baseline. Consecutive symbols ({2}{U}{U}:) form one box with the trailing punctuation (: , . ; )) attached as a nested TextBlock (SymbolGroup.tail), so a cost never splits across lines.
    • Typesetter.locale (Option<parley::Language>) is passed to parley as the text language: it picks Japanese versus Chinese glyph forms and locale-specific forms. compose::prepare sets it from DesignLang::locale() only for languages other than Spanish and English; for those two it stays None, so their layout (and pixels) are exactly what they were before more languages existed.
    • Typesetter.substitutions is a list of (char, replacement) pairs set from the pack's substitutions map (compose::prepare), for characters a pack font lacks.
  3. TextStyle (family, weight, size px, line_spacing, colour, TextAlign, small_caps, highlight, ability) is the paint-ready style. TextBlock is a laid-out paragraph (width, height, base, plus last_line_width()).
  4. Fitting:
    • fitted_line_with_base (title and type line): see Title squeeze below.
    • typeset_rules: stacks rules paragraphs and flavour text with Spacing { paragraph: 0.32, flavor: 0.75 } (multiples of the font size) and records where the divider line goes between rules and flavour.
    • fit_rules: if the box is too tall, binary-searches the font size down in steps of 0.1 pt (step) to min_size; at the minimum it tightens spacing (paragraph 0.12, flavor 0.45) and, if it still does not fit, returns the overflow in FitResult.excess.

paint.rs: glyphs to pixels

paint_block(canvas, block, x, y, text_paint, symbols) walks the parley lines. For every glyph run it fetches the outline with skrifa unhinted (works with variable fonts via normalised coordinates), accumulates one tiny_skia path per run through the Pen outline pen, and fills it with anti-aliasing. Details:

  • TextPaint { x_scale, color }: x_scale is the horizontal squeeze factor (text is condensed by scaling x, not by switching fonts); color overrides the text colour (used for the drop shadow).
  • Synthetic italic (synthesis().skew()) is applied as a shear in the pen; synthetic bold draws an extra stroke of 0.035 * size.
  • Inline boxes paint their symbols through Symbols::paint; in shadow mode a symbol becomes a circle of the shadow colour. Missing symbols are returned as codes (painted grey) and surface as DesignWarning::MissingSymbols.
  • paint_text_box paints a rules box and the flavour divider; has_glyph(data, c) checks a font for a character.
  • Colour glyphs (emoji): before taking an outline, each glyph is offered to emoji::paint_glyph, which asks skrifa for its colour layers (color_glyphs) and paints them in place with a ColorPainter (GlyphPainter in emoji.rs). It uses the same baseline, size and x_scale as the text. In shadow mode (TextPaint.color) every layer takes the shadow colour.
    • Brushes: solid colours from CPAL palette 0 (0xFFFF = the text colour), and linear, radial and sweep gradients as tiny_skia LinearGradient / RadialGradient / SweepGradient shaders. Almost every Noto emoji uses gradients. A gradient tiny-skia cannot build (degenerate, negative radius) falls back to the average colour of its stops (mid).
    • Composite layers: push_layer opens an offscreen Pixmap the size of the canvas; fills go to the topmost one; pop_layer draws it onto the layer below (or the canvas) with the BlendMode matching the COLR CompositeMode (to_blend_mode).
    • Clip versus brush transform: a glyph clip (Clip::Glyph) stores the transform active when it was pushed. Noto pushes a further transform for the gradient after the clip, so the fill paints the path with the clip's transform and gives the shader only the difference (current transform relative to the clip's). Using the current transform for the path would move the outline.
    • is_emoji(c): whether the emoji font has c (and c >= U+2190, below which any text font has it). Used by the render hash, see Render hash and emoji.

symbols.rs: mana symbols

Symbols holds parsed usvg::Trees by code ("T", "2/U", "W/P"), keyed by code() (braces stripped, upper case). Scryfall's SVGs are downloaded and stored by the app (symbols_status command, refreshed after 30 days, SYMBOLS_EXPIRY); see Designer-App-Layer. Symbols::new() always includes two built-in footer icons from assets/icons/: {BRUSH} (brush) and {STAR} (star). The footer text maps the characters ★ and ✎ to them.

CustomSymbols is the pack-supplied layer (SVG or PNG per code, pixel flag for nearest-neighbour scaling). Symbols::with_custom(Arc<CustomSymbols>) returns a view where own symbols shadow Scryfall's; codes the pack lacks fall through to Scryfall. PNG symbols are fitted without distortion, centred in the square.

render.rs: painting one face

paint_face(engine, e, lang, assets, style, warnings, options) -> Piece paints a face on a Canvas (a tiny_skia::Pixmap plus the mm-to-px factors kx, ky and the canvas size in mm). Everything is specified in millimetres on a 63 x 88 card (or the style's own size); the canvas converts. Another deck card size (63.5 x 88.9 or 65 x 90 mm) only changes the canvas in pixels, so the 63 x 88 geometry is stretched to it (kx and ky differ by less than 1 %). The same function paints a normal card, half of a split card, the aftermath strip, a landscape plane… because PieceOptions (face, body, transparent, width_px, height_px, indicator, other_face, no_footer, no_art, adventure) and the StyleDef passed in say what to draw.

Step by step

  1. Canvas. Canvas::new(w_mm, h_mm, width_px, height_px). Filled with opaque black unless options.transparent.
  2. Colour choice. frame_colors → frame_choice:
    • FrameColor::Palette / Gradient / Custom are taken as given.
    • Auto: one card colour gives its palette; two give a gradient of the two (in order); three or more give gold; none gives artifact (type contains Artifact) or colorless. A colourless land uses its colour identity if any (so a dual land is coloured), else the land palette. Face colours win over card colours.
    • Palettes (PaletteDef) become Tones { light, mid, dark, tint, text_box, ink }; a custom colour is turned into tones by lightening/darkening; a gradient mixes the two (Tones::blend). A palette missing from the pack renders grey.
  3. Rules-box mode. From FrameOptions.rules_box (Auto uses the style's defaultBox: Tint = colour tint at 0.80 opacity, Light = light box at 1.0; Dark = near-black 0.85; Light = cream 0.92; Tint{hex} = 0.80 for a 6-digit hex; an 8-digit #rrggbbaa uses its alpha as the opacity). The fine-tuning rules_box_opacity pushes the opacity toward 1 (the editor no longer offers it: the only opacity control is "Tint opacity", next to the tint colour; a value saved before still applies until "Reset all"). The text ink (boxInk) is white or the palette ink depending on the perceived luminance of the box.
  4. SVG variables. A BTreeMap<String,String> (vars) with defs (the gradients) and the colours listed in Frame-Packs, later extended with the dynamic-box geometry.
  5. Rules text first. The body is laid out before anything is painted because the growing rules box moves the title bar and the artwork edge:
    • face_content → a Content (plain text, sections with badges, or adventure columns; see Designer-Composition).
    • Dynamic box (style has text_box): try the "comfortable" height (comfort_height) letting the font shrink down to 75 % (COMFORT_FONT_SCALE) unless the user fixed a rules size; if that does not fit, use max_height with the full font and shrink as needed down to a 6 pt floor. If the last line would run into the power/toughness box, the bottom padding is raised and the fit redone. The resulting geometry becomes numeric variables for pack expressions (yRules, rulesHeight, yType) and SVG variables (yRules, rulesHeight, yType, yType04). Gotcha: yRules / rulesHeight mean the text area in slot expressions (nums) but the whole box in SVG vars.
    • Fixed box (no text_box): fit inside the rules slot (minus the MDFC strip); the text is vertically centred (verticalAlign can change that).
    • Overflow at the floor raises DesignWarning::TextDoesNotFit { slot: "rules", excess } (mm).
  6. Background layers (StyleDef.background) are painted under the artwork. Skipped when no_art (live-drag layer), because they would cover the artwork the UI places underneath.
  7. Artwork. paint_art(l, img, slot, framing):
    • No rotation: one step crop plus Lanczos3 resize (rescale with ResizeOptions::crop). Zoom >= 1; offsets in [-1, 1] move within the slack on each axis.
    • With rotation: scale up to cover the rotated rectangle, then draw with a bicubic rotation transform.
    • No image: a neutral dark gradient (no_art), unless the style has background layers. The slot may use box variables so the art reaches the type bar.
    • The result is returned to the caller as Piece.art (fractions of the canvas) for render_overlay.
  8. Art window (artWindow): window_svg paints black outside the window with rounded corners (radius from the style, or FineTuning.art_radius). Just before it, the art fade (FineTuning.art_fade or the style's artFade, plus the extension) is painted over the artwork.
  9. Pack layers (DrawnCard::layers). Each Layer is skipped unless its when condition holds for the Facts (crown/pt/ribbon/emblem set here, the rest from facts_of). Then:
    • rulesBoxTint layers paint the requested box tint in their zone (box_tint) and nothing else;
    • PNG layers (png_layer) resolve {color}/{color1}/{color2} in the path (Layer::png_for), evaluate the zone expressions with the box variables (a zone that references a variable the card lacks is skipped), and paint with png_fragment (full stretch; with from only that piece of the PNG, on its own spot unless en says otherwise; with mask cut by that PNG's alpha) or png_sliced (spans: top and bottom slices keep proportions, only the middle stretches); blend (blend) and opacity apply through blend_paint. The sized result is cached by png_images::fragment (key: pack hash, path, piece, mask, size, scaling), so dragging the art does not redo the crop and mask; the frame colour effects (gradient, custom tint) apply to the piece the same way;
    • SVG layers are fill_template-ed with the variables and rendered by resvg over the whole canvas (Canvas::svg). A layer not found in the pack falls back to the builtin pack's files.
    • If the style has artWindow.repaint and the user set art_radius, layers are split at repaintAfter: after the first group, repaint_window re-paints the artwork (or black) over the zones where the frame image drew a baked-in curve, then the remaining layers follow. The zones are repainted whole, also beside the type bar when a short dynamic box pushes the bar down into them (clipping them below the bar used to leave the image's baked-in curve there as a black wedge); the pack therefore puts every layer that moves with yType (type bar, box) after repaintAfter, so the bar's rounded ends stay on top.
  10. Texts, in this order: cost (cost: right-aligned symbols, with a dark circle behind each unless the pack has own symbols; the title width is reduced to stay left of the cost when both are on the same row), face indicator (sun/moon/triangles for transform and MDFC, pushes the title right), title, ribbon with the original name (ribbon), type line (width reduced by the label pill), label pill (label: rarity/legendary/basic land type), emblem (image, fitted undistorted), fullArt colour symbol, rules content (paint_content) or dungeon rooms (paint_dungeon), Vanguard hand/life, MDFC other-face strip (other_face_strip), power/toughness (or loyalty, or defense; pt_text), footer (footer).
  11. Warnings (missing name, hand-edited rules, missing fonts for the script, no official text in the design language) are added and the Piece returned.

Afterwards compose::render removes duplicate warnings, adds MissingSymbols (excluding the built-in icons), and applies the corner mask: FineTuning.card_radius when set (screen and print), else the style's radius on screen and square for print. from_pixmap un-premultiplies to RgbaImage.

Title and type-line squeeze

DrawnCard::line(name, paragraph, max_width, squeeze) → fitted_line_with_base:

  1. Lay the text out on one line. The line is always squeezed to at least squeeze_base (collection/card "minimum squeeze", 1.0 = none, only for the title and card_type slots).
  2. If it still does not fit, squeeze horizontally (TextPaint.x_scale) down to squeeze_min (the limit, 55-75 %).
  3. If even that does not fit, shrink the font size just enough, and report DesignWarning::TitleShrunk { slot }.

Decision rationale: condensing the glyphs a little keeps the pack's font size and card look; shrinking is the last resort. Helper texts (centered_text, left_text, used by badges and the MDFC strip) use a fixed 0.6 limit.

Fine tuning (FineTuning)

Applied inside DrawnCard::slot, text_scale, slot_text_style, paint_face and footer:

Field Effect
title, cost, type_line, emblem, pt, footer (mm) Added to the slot y (DrawnCard::slot).
rules (mm) Added when the rules content is painted (the slot also measures the box, so it is not moved in slot).
title_size, cost_size, type_size, rules_size, pt_size, footer_size Multiply the font size of that role (text_scale; the ribbon follows title_size). cost_size scales the side of the mana symbols in DrawnCard::cost: they stay right-aligned and centred on the slot's height, and the title gets the room they free (cost_end). With rules_size set the comfortable-height shrink is skipped: the box grows as needed and the font only drops if even the maximum box is too small.
rules_line_spacing, footer_line_spacing Multiply the line height / footer row pitch.
rules_box_opacity See step 3.
art_radius, card_radius Corner radii (mm), see steps 8 and the corner mask.
art_fade (mm) Fades the bottom edge of the artwork into black (fade_bottom, painted over the artwork and under the pack layers: smooth at both ends, fully black 1.5 mm before its end because the frame usually covers that edge). None uses the style's artFade (the built-in extended frame: 12 mm with 7 mm of extension); 0 turns it off.
art_fade_extension (mm) How far the artwork continues below its window, fading out (the variable artExtension, so the frame's black starts that much lower; the fade ends there). With an own art_fade the extension is the card's own (or none); without it, the card's if set, else the style's artFadeExtension.
rules_box_height (mm) Raises (positive) or lowers (negative) the top edge of the rules box; exposed to packs as the variable boxRaise. Dynamic box: max_height and comfort_height grow by the positive amount, the requested height is the natural one plus the offset, and with a negative value the text is refitted into the lower box (smaller font if needed, never below padding + 3 mm). Fixed frames (built-in extended and classic) move their art, type line, emblem and box edge with boxRaise. Image frames ignore it, except those that declare a text_box (the Original pack, see Frame-Packs); Balatro ignores it.
rules_box_dynamic None = as the frame: dynamic in the house borderless, fixed in the built-in extended and classic and in the three Original styles (GrowingBox.fixed_by_default). Some(true): dynamic everywhere; in a fixed frame that uses boxRaise the box is shortened automatically when the text is short (crop, at most MAX_BOX_HEIGHT_MM, 10 mm) by writing a negative boxRaise, re-evaluating the rules slot and refitting the text (undone if the box did not really shrink). Some(false): the box always keeps max_height (the natural-height clamp is skipped and comfort_height is ignored) and the rules text is centred vertically in it, like in the fixed boxes (fixed_growing_box in paint_face; a growing box at its natural height keeps the text at the top). Balatro does not change.

Colour tinting for image frames (FrameExtra)

Image-based packs (Original, Balatro) have one PNG per colour instead of a gradient SVG. For layers whose path contains {color} only:

  • FrameExtra::Gradient(b): paint the first palette's PNG, then the second palette's PNG with fade_in_to_the_right (alpha ramp from 35 % to 65 % of the card width).
  • FrameExtra::Tint(color): take the neutral (colorless) PNG and tint_image it, an overlay-style blend driven by luminance that keeps highlights and shadows.
  • FrameExtra::Unchanged: the PNG of the chosen palette. Two-colour cards in Auto stay on gold (frame_key), and so do the frame's drawn SVG pieces (the original-name ribbon, the crown cover…): when the style paints its frame from a {color} PNG (is_image_frame), frame_colors_for gives paint_face the gold palette without a second colour, so #frame has no gradient and everything matches. A gradient chosen by hand still blends (the PNG fuses the second palette too).

PNG caches

render::png_images keeps two process-wide LRU lists (ORIGINALS: decoded PNGs; SIZED: resized to the exact pixel size), each capped at 160 MiB of RGBA. Keys include Pack.fingerprint, so a modified pack never reuses old pixels. Repainting the same frame while dragging artwork therefore costs only the artwork.

Rules box and secondary text helpers

DrawnCard exposes centered_text, left_text, symbols_in_row and draw_shape (an SVG fragment in millimetres sharing the card's gradients). bodies.rs uses them to draw badges (Designer-Composition).

Warnings produced by the engine

DesignWarning Raised by
TextDoesNotFit rules text overflows at the 6 pt floor
TitleShrunk title/type had to shrink after squeezing
MissingName no thematic name for the face and language
RulesEdited rules_override present
NoOfficialText the design language has no printing (CardData::is_textless_in(lang): Spanish via textless_es, other languages via textless; always for Romanian, Polish, Dutch and Ukrainian, which Scryfall does not print); rules are the English Oracle
MissingFonts { lang } the language's script has no loaded font (Fonts::has_writing_system false: Japanese, Korean or Chinese before their font is downloaded)
FontNotFound collection font not loaded
MissingSymbols symbol code with no SVG/PNG
NoRibbon original name in ribbon requested, style has no ribbon slot
PackWithoutLayout, StyleNotInPack, UnknownLayout see Designer-Composition and Frame-Packs
CollectionLost added by the app, not the engine

Design languages

A design can be painted in any of 15 languages. The codes are Scryfall's and the same as the interface (src/lib/languages.ts), so the UI, design and deck languages share keys.

Item Where Meaning
DesignLang model.rs Es En Fr De It Pt Ro Pl Nl Ru Uk Ja Ko Zhs Zht. ALL lists them in that order, which also decides the key order when saving a ByLang and must not change. code() / from_code() (Scryfall code), has_printed_cards() (false for Ro, Pl, Nl, Uk: Scryfall has no cards in them, rules come from the English Oracle), writing_system() → WritingSystem (Latin, Cyrillic, Japanese, Korean, SimplifiedChinese, TraditionalChinese: which fonts are needed), locale() (BCP-47, e.g. zh-Hant-TW).
ByLang<T> model.rs es and en always, plus others: BTreeMap<DesignLang, T> flattened into the same object. Saved as { "es": …, "en": …, "fr": … }: es and en first and always (2.5.x requires them and ignores the rest), the others only if present, so a design that only uses Spanish and English is saved byte for byte as before. Deserialize is hand-written and tolerant: missing es/en become defaults, unknown codes (from a newer version) are ignored. get(lang) falls back to en; get_mut(lang) creates the entry; has(lang) says whether it has its own value. ts-rs cannot flatten a generic map, so others is #[ts(skip)] and the frontend reads/writes the extra keys through src/lib/by-language.ts.
FaceDesign::texts(lang) model.rs The face texts in lang. Languages other than Spanish and English do not fall back to the English texts: without their own, the name is the printed one and the rules the official ones (the app copies a thematic name into a new language when it is chosen). has_manual_rules(): any language has rules_override.
FaceData.printed_names model.rs Printed name per code for the other languages (printed_name_es stays for Spanish, so 2.5.x keeps reading it; English is name). Read and write with printed_name(lang) / set_printed_name(lang, name). Not serialised when empty.
CardData.textless model.rs Codes of the other languages without a printing (textless_es stays for Spanish). is_textless_in(lang), set_textless(lang, without) (kept sorted), has_language(lang) (es/en always; otherwise known to be unprinted or every face has rules in that language).

Engine text that is not card data:

  • engine_texts.rs: level_word(lang) (the level word of a leveler, «NIVEL», «STUFE», «等级»…), level_words() (all of them, to recognise ranges in any language), fuse_reminder(lang) / fuse_word(lang) / is_fuse_line(line) (Fuse keyword and reminder), and footer_code(lang) (the {lang} code of the footer template). Printed languages take their words from real cards on Scryfall (noted next to each value); Romanian, Polish, Dutch, Ukrainian and Korean Fuse have no official source. The footer codes were checked on real cards (FR, DE, IT, JP, KR, CS, CT, RU); Spanish stays ES although Spanish cards print SP, because changing it would change every Spanish card already made.
  • language_types.rs: offline type lines for every design language except English (type_line_in(en, lang)). The English line always has a closed vocabulary (Scryfall's catalogs: 7 supertypes, 19 card types and about 500 subtypes), so the data is a fixed table, not a request. It has two layers. (1) assets/printed-types.json, generated by scripts/printed-types.mjs: for each language with printed cards, the whole type part in English → how Scryfall printed it («Legendary Artifact Creature» → «Criatura artefacto legendaria»; whole phrases, because order, gender and case change per language), and each subtype alone («Elf» → «Elfo»). It is read once (OnceLock) and compiled into the binary; the app never calls Scryfall for it. Subtypes no card carries alone («Druid») are deduced from lines with several («Elf Druid»). Rerun the script when a set adds types: it merges into the existing file and saves after each language. (2) The hand-written tables (FR, DE, …) with the separator and subtype joiner per language, each phrase noting the real card it comes from; they are the only source for Romanian, Polish, Dutch and Ukrainian (no printed cards, no official source) and for the types no foreign card shows (Token, Emblem, Dungeon, Conspiracy, Vanguard…). Order: JSON phrase, then table phrase; per subtype, table, then JSON, then the English word. Italian changes word order with several subtypes, so unknown ones go in English order (joiner: None). If the types themselves are unknown the result is None (Scryfall's printing, or English, wins). Spanish has no table (ES only gives the subtype joiner); draft::spanish_type_line remains as its last resort.
  • structure.rs: level ranges (level_words), class levels and case headers («To solve», «À résoudre», «解明条件»… from Case of the Shattered Pact) are recognised in every printed language, so sections and badges work whatever the design language.

Render hash and emoji

effective::fingerprint hashes own_language_only(e, lang): the design without the texts of languages that are not painted, so editing one language never re-renders another. For Spanish and English the reduced design is exactly what it was before more languages existed (the other languages are dropped too), so adding languages did not change their hashes or their cached renders. (The English names of 4.1.2 did change the serialised design, and with it the hashes: those cards were repainted once.) When the serialised design contains an emoji (emoji::is_emoji), |emoji-noto is added to the hash: switching the emoji font re-renders only cards with emoji, instead of every card as bumping ENGINE_VERSION would. The same trick marks other targeted repaints: |ficha-estilo-del-pack (tokens), |mdfc-sin-pestana and |tramos-del-pack (faces whose body is leveler, station or prototype, since their section P/T boxes now use the pack's own box) and |piezas-en-oro (two-colour cards with the frame colour on automatic, render::is_auto_two_color, whose drawn pieces go gold on image frames; without it the cache kept serving the old gradient ribbon).

Compatibility tests

  • effective::tests::spanish_and_english_fingerprints_are_unchanged: fixed hashes for Spanish and English, so that adding languages (or anything a card does not have) does not repaint it. They changed once, with the names of 4.1.2: those cards were repainted once.
  • model::tests::old_design_rewrites_with_only_new_names: tests/compatibility/design-2.5.9.json is read and written back with everything it had, byte for byte but for the names that changed in 4.1.2 (sinTextoEs is written as textlessEs).
  • model::tests::other_language_saves_after_es_and_en_and_old_version_reads_it: a design with another language saves it after es and en, the old two-field struct still reads it, and an unknown language key is ignored.

Golden tests

Directory: src-tauri/crates/proxy-core/tests/ (goldens.rs, layouts.rs, common/mod.rs) and reference images under tests/goldens/.

  • goldens.rs → goldens_of_base_cases: 13 base cases (legendary creature, ribbon variant, extended legendary, two-colour wall, long title, sorcery, creature in classic, artifact in borderless and classic, extended land, full-art basic, extended and classic tokens) rendered at WIDTH = 420 px with the builtin pack, built-in fonts, synthetic art and synthetic symbols (common: hand-drawn so there are no rights issues), print output. Each image is compared to tests/goldens/<name>.png; a case fails at 0.5 % of pixels differing by more than 8/255 in any channel (common::difference). The test also asserts no MissingSymbols warning.
  • same_renders_give_same_bytes: identical inputs give identical bytes; print output is opaque; screen output has a transparent corner pixel; poker size renders at the right aspect.
  • changing_a_pack_color_changes_the_golden: editing a palette changes Pack.fingerprint and the image.
  • goldens_in_other_languages: the same card in French, Russian and Romanian against tests/goldens/language-fr.png, language-ru.png, language-ro.png, asserting no MissingFonts and NoOfficialText only for Romanian (no printing). golden_in_japanese (ignored) compares language-ja.png; it needs the downloaded Japanese font: PB_CJK=<NotoSansJP[wght].ttf> cargo test -p proxy-core --test goldens -- --ignored golden_in_japanese.
  • tests/layouts.rs → goldens_of_layouts, large_cards_come_out_at_their_size (see Designer-Composition).
  • Ignored, run on demand with environment variables: timings (timings), original_with_its_images (PB_ORIGINAL, folder of Card Conjurer frames; renders classic, extended and borderless), original_colors (same three styles with every frame colour and rules box), balatro_with_its_images and balatro_against_the_author (PB_BALATRO, PB_AUTOR, PB_SALIDA), free_fonts_by_eye (PB_GF), balatro_matrix in layouts.rs. These need external assets and are for eyeballing, not CI.
  • Updating goldens: PB_ACTUALIZAR_DORADOS=1 cargo test -p proxy-core --test goldens (and --test layouts) rewrites the images. Do it only for intended visual changes and review the diff; also bump ENGINE_VERSION when pixels change on purpose so caches refresh.
  • Unit tests live next to the code: render.rs (palettes, gradients, styles, layouts, footers, tinting, sizes), compose.rs, bodies.rs, text.rs, paint.rs, pack.rs, effective.rs, engine_texts.rs, language_types.rs, structure.rs.

Also src-tauri/crates/proxy-core/examples/design.rs renders sample cards to disk for eyeballing, and examples/prototype.rs is the early prototype kept as a reference (not app code).

Failure modes

Failure Behaviour
Canvas of impossible size DesignError::Canvas (pixel width is clamped to at least 16 in render; tiny-skia pixmap creation can still fail)
Invalid font file DesignError::InvalidFont
Corrupt symbol DesignError::InvalidSymbol
Pack layer file missing at paint time the layer is skipped silently (packs are validated on load, so this means a builtin-fallback case)
Style missing from the pack builtin pack's style is used; then the pack's borderless; finally DesignError::Canvas

See also

Documentation · Documentación

Language: English · Español

Use and build · Uso y desarrollo

Architecture · Arquitectura

Data · Datos

Getting cards · Conseguir cartas

Layout, images, PDF · Maquetación, imagen y PDF

Card designer · Diseñador de cartas

Game table · Mesa de juego

Mobile · Móvil

Frontend · Frontend

Reference · Referencia

Clone this wiki locally