Skip to content

Commit

Permalink
add support for text-anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
drexhage committed Nov 13, 2023
1 parent aab48a4 commit b900ddc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

### Added
- Adding support for text-anchor
- Rounding of all values + options to change the number of after decimal
- News tests for complete files
- Cleaning of the comments
Expand Down
18 changes: 17 additions & 1 deletion svg2tikz/tikz_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ def filter_tag(node):
# Format:
# 'svg_name' : ('tikz_name', value_type, data)
PROPERTIES_MAP = {
"text-anchor": (
"anchor",
DICT,
{
"start": "south west",
"middle": "south",
"end": "south east"
}
),
"opacity": ("opacity", SCALE, ""),
# filling
"fill-opacity": ("fill opacity", SCALE, ""),
Expand Down Expand Up @@ -1288,7 +1297,14 @@ def _output_group(self, group):
elif node.TAG in ["text", "flowRoot"]:
pathcode = self._handle_text(node)

goptions += ["anchor=south west"]
# Check if the anchor is set, otherwise default to south west
contains_anchor = False
for goption in goptions:
if goption.startswith("anchor="):
contains_anchor = True
if not contains_anchor:
goptions += ["anchor=south west"]

optionscode = f"[{','.join(goptions)}]" if len(goptions) > 0 else ""
# Convert a rotate around to a rotate option
if "rotate around={" in optionscode:
Expand Down
2 changes: 1 addition & 1 deletion tests/testfiles/switch_simple.tex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


\begin{scope}[shift={(-0.0132, 0.189)}]
\node[anchor=south west] (text2) at (2.249, 5.3975){vrai};
\node[anchor=south] (text2) at (2.249, 5.3975){vrai};



Expand Down
10 changes: 5 additions & 5 deletions tests/testfiles/text_fill_color.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@

\def \globalscale {1.000000}
\begin{tikzpicture}[y=1cm, x=1cm, yscale=\globalscale,xscale=\globalscale, inner sep=0pt, outer sep=0pt]
\node[anchor=south west] (text2) at (3.385, 6.5697){Default};
\node[anchor=south] (text2) at (3.385, 6.5697){Default};



\node[text=red,anchor=south west] (text2-3) at (3.385, 6.2094){Red};
\node[text=red,anchor=south] (text2-3) at (3.385, 6.2094){Red};



\node[text=lime,anchor=south west] (text2-6) at (3.385, 5.8491){Green};
\node[text=lime,anchor=south] (text2-6) at (3.385, 5.8491){Green};



\node[text=blue,anchor=south west] (text2-3-7) at (3.385, 5.4889){Blue};
\node[text=blue,anchor=south] (text2-3-7) at (3.385, 5.4889){Blue};



\node[text=black,anchor=south west] (text2-5) at (3.3992, 5.1286){Black};
\node[text=black,anchor=south] (text2-5) at (3.3992, 5.1286){Black};



Expand Down

0 comments on commit b900ddc

Please sign in to comment.