Skip to content

Commit

Permalink
Merge pull request #170 from drexhage/feature/text-anchor
Browse files Browse the repository at this point in the history
Add support for text-anchor
  • Loading branch information
ldevillez authored Nov 17, 2023
2 parents 516e4a0 + ebd3edc commit f142e3a
Show file tree
Hide file tree
Showing 6 changed files with 68 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
14 changes: 13 additions & 1 deletion svg2tikz/tikz_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ 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 +1293,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
36 changes: 36 additions & 0 deletions tests/testfiles/text.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions tests/testfiles/text.tex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@



\node[anchor=south west,line width=0.0265cm] (text5) at (1.0, 28.2){Start Text};



\node[anchor=south,line width=0.0265cm] (text6) at (1.0, 27.7){Middle Text};



\node[anchor=south east,line width=0.0265cm] (text7) at (1.0, 27.2){End Text};




\end{tikzpicture}
\end{document}
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 f142e3a

Please sign in to comment.