Skip to content

Commit 45e41a3

Browse files
authored
Merge pull request #56 from EvilJordan/master
New option "--fillonly"
2 parents c83881c + 7940a6b commit 45e41a3

File tree

11 files changed

+75
-6
lines changed

11 files changed

+75
-6
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Example usage:
2424
2525
--charboxsize WxH Character box size (use pixel units instead of font units)
2626
--colorscheme NAME Color scheme
27+
--fillonly Remove strokes from SVG output (use fills only)
2728
--fontfile PATH Font file to use and embed
2829
--fontname NAME Font name
2930
--fontref URL External font URL to use
@@ -69,7 +70,7 @@ go build -o ansisvg .
6970

7071
## Fonts
7172

72-
`ansisvg` can either use system-installed fonts (`-fontname`), link to a webfont on a HTTP server (`-fontref`) or embed a webfont from the local filesystem (`-fontfile`).
73+
`ansisvg` can either use system-installed fonts (`--fontname`), link to a webfont on a HTTP server (`-fontref`) or embed a webfont from the local filesystem (`--fontfile`).
7374

7475
### Compatibility issues
7576

@@ -79,17 +80,17 @@ go build -o ansisvg .
7980

8081
### Variations of custom fonts (regular/bold/italic)
8182

82-
* System wide fonts (`-fontname`) get correctly rendered with variations, but when using external fonts with `-fontref` or `-fontfile` the SVG viewer knows only the regular variant and will try to render italic/bold text 'extrapolated' from it which may look different than the actual font variation. To use the actual bold/italic font variants, different woff2 files have to be used for the respective text styles which needs additional CSS code (currently not supported by `ansisvg`).
83+
* System wide fonts (`-fontname`) get correctly rendered with variations, but when using external fonts with `--fontref` or `--fontfile` the SVG viewer knows only the regular variant and will try to render italic/bold text 'extrapolated' from it which may look different than the actual font variation. To use the actual bold/italic font variants, different woff2 files have to be used for the respective text styles which needs additional CSS code (currently not supported by `ansisvg`).
8384

84-
* Bold style 'extrapolated' from the regular font may even break monospace alignment. Use `-grid` option to mitigate that.
85+
* Bold style 'extrapolated' from the regular font may even break monospace alignment. Use `--grid` option to mitigate that.
8586

8687
## Font-relative vs. pixel coordinates
8788

88-
By default, `ansisvg` uses font-relative `ch`/`em` coordinates. This should make SVG dimensions and line/character spacing consistent with font family/size. When SVG dimensions and/or text coordinates are off, it is possible to force explicit pixel units for coordinates by specifying `-charboxsize` in X/Y pixel units, e.g. `8x16`.
89+
By default, `ansisvg` uses font-relative `ch`/`em` coordinates. This should make SVG dimensions and line/character spacing consistent with font family/size. When SVG dimensions and/or text coordinates are off, it is possible to force explicit pixel units for coordinates by specifying `--charboxsize` in X/Y pixel units, e.g. `8x16`.
8990

9091
* Inkscape currently [cannot deal with SVG size expressed in font-relative units](https://gitlab.com/inkscape/inkscape/-/issues/4737), a quick workaround is Ctrl-Shift-R (resize page to content).
9192

92-
* Some SVG processing tools like [asciidoctor](https://docs.asciidoctor.org/pdf-converter/latest/image-paths-and-formats/#image-formats) require the presence of the `viewBox` attribute. Use `-charboxsize` option to enable this attribute (it only works with pixel dimensions).
93+
* Some SVG processing tools like [asciidoctor](https://docs.asciidoctor.org/pdf-converter/latest/image-paths-and-formats/#image-formats) require the presence of the `viewBox` attribute. Use `--charboxsize` option to enable this attribute (it only works with pixel dimensions).
9394

9495
## Margin size
9596

@@ -98,7 +99,11 @@ With `--marginsize` a margin can be defined, so there is a bit of empty space (o
9899

99100
## Consolidated text vs. grid mode
100101

101-
By default, `ansisvg` consolidates text to `<tspan>` chunks, leaving the X positioning of characters to the SVG renderer. This usually works well for monospace fonts. However if not all glyphs involved are monospace (e.g. when exotic characters are used, making the SVG renderer fall back to a different font for those characters) then the alignment will be off; this can be worked around with `-grid` mode which will make `ansisvg` put each character to explicit positions, making the SVG bigger and less readable but ensuring proper positioning/alignment for all characters.
102+
By default, `ansisvg` consolidates text to `<tspan>` chunks, leaving the X positioning of characters to the SVG renderer. This usually works well for monospace fonts. However if not all glyphs involved are monospace (e.g. when exotic characters are used, making the SVG renderer fall back to a different font for those characters) then the alignment will be off; this can be worked around with `--grid` mode which will make `ansisvg` put each character to explicit positions, making the SVG bigger and less readable but ensuring proper positioning/alignment for all characters.
103+
104+
## Illustrator Issues
105+
106+
When handling ANSIs primarliy composed of block characters, e.g. █, ░, ▒, etc., a `stroke` is created by default in the output SVG that may cause overlapping of characters when viewed in Illustrator. The `--fillonly` mode is provided to remove `stroke` from the output SVG. This works especially well when combined with `--grid` and `--charboxsize`.
102107

103108
## Tricks
104109

ansisvg

5.44 MB
Binary file not shown.

ansitosvg/ansisvg.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Options struct {
2121
ColorScheme string
2222
Transparent bool
2323
GridMode bool
24+
FillOnly bool
2425
LineHeight float32
2526
}
2627

@@ -31,6 +32,7 @@ var DefaultOptions = Options{
3132
MarginSize: xydim.XyDimFloat{X: 0, Y: 0},
3233
ColorScheme: "Builtin Dark",
3334
Transparent: false,
35+
FillOnly: false,
3436
LineHeight: 1.0,
3537
}
3638

@@ -143,6 +145,7 @@ func Convert(r io.Reader, w io.Writer, opts Options) error {
143145
NrLines: ad.MaxY + 1,
144146
Lines: lines,
145147
GridMode: opts.GridMode,
148+
FillOnly: opts.FillOnly,
146149
}
147150
return s.Render(w)
148151
}

cli/cli.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func Main(env Env) error {
3636
var listColorSchemesFlag = fs.Bool("listcolorschemes", false, "List color schemes")
3737
var transparentFlag = fs.Bool("transparent", ansitosvg.DefaultOptions.Transparent, "Transparent background")
3838
var gridModeFlag = fs.Bool("grid", false, "Grid mode (sets position for each character)")
39+
var fillOnlyFlag = fs.Bool("fillonly", ansitosvg.DefaultOptions.FillOnly, "Remove strokes from SVG output (use fills only)")
3940
var helpFlag bool
4041
fs.BoolVar(&helpFlag, "h", false, "")
4142
fs.BoolVar(&helpFlag, "help", false, "Show help")
@@ -144,6 +145,7 @@ Example usage:
144145
ColorScheme: *colorSchemeFlag,
145146
Transparent: *transparentFlag,
146147
GridMode: *gridModeFlag,
148+
FillOnly: *fillOnlyFlag,
147149
},
148150
)
149151
}

cli/testdata/fillonly.ansi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
              
2+
    TEST!!    
3+
              

cli/testdata/fillonly.args

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--fillonly

cli/testdata/fillonly.svg

Lines changed: 44 additions & 0 deletions
Loading

cli/testdata/help-short-flag.stdout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Example usage:
66

77
--charboxsize WxH Character box size (use pixel units instead of font units)
88
--colorscheme NAME Color scheme
9+
--fillonly Remove strokes from SVG output (use fills only)
910
--fontfile PATH Font file to use and embed
1011
--fontname NAME Font name
1112
--fontref URL External font URL to use

cli/testdata/help.stdout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Example usage:
66

77
--charboxsize WxH Character box size (use pixel units instead of font units)
88
--colorscheme NAME Color scheme
9+
--fillonly Remove strokes from SVG output (use fills only)
910
--fontfile PATH Font file to use and embed
1011
--fontname NAME Font name
1112
--fontref URL External font URL to use

svgscreen/svgscreen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ type Screen struct {
9696
NrLines int
9797
Lines []Line
9898
GridMode bool
99+
FillOnly bool
99100
Dom SvgDom
100101
}
101102

0 commit comments

Comments
 (0)