Skip to content

TikZ backend: fill vs draw dispatch + \definecolor preamble #53

@yueswater

Description

@yueswater

Sub-issue of #50.

Problem

The renderer needs to correctly dispatch between \draw and \filldraw
based on whether rgbFace is provided, and honour the GraphicsContext
stroke color, line width, and dash pattern. Emitted colors must also be
declared via \definecolor in the preamble so the output snippet is
self-contained and portable.

Proposed fix

def _cmd(self, gc, rgbFace):
    stroke = _rgb_to_tikz(gc.get_rgb())
    lw     = gc.get_linewidth()
    if rgbFace is None:
        return rf'\draw[color={stroke}, line width={lw:.2f}pt]'
    fill = _rgb_to_tikz(rgbFace)
    return rf'\filldraw[color={stroke}, fill={fill}, line width={lw:.2f}pt]'

Maintain a color registry on the renderer; emit every unique color as a
\definecolor{name}{rgb}{r,g,b} line in the output preamble.

Acceptance criteria

  • Unfilled paths emit \draw[...] with correct stroke color and line width.
  • Filled paths emit \filldraw[...] with both color= (stroke) and
    fill= set.
  • All referenced colors are declared via \definecolor once in the preamble.
  • Dash patterns from gc.get_dashes() are translated to TikZ
    dashed / dotted / custom dash pattern=... as appropriate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions