🌐 AI搜索 & 代理 主页
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7e79af9
Added text-as-path functionality to backend_ps.py
gigoiy Dec 9, 2025
b28cd17
Removed trailing whitespace in backend_ps.py
gigoiy Dec 9, 2025
c13f88a
Properly implemented the new feature from
gigoiy Dec 10, 2025
7819ead
Fixed coding style
gigoiy Dec 10, 2025
dd02737
Removed trailing whitespace
gigoiy Dec 10, 2025
7e7790e
Updated typing.py to include ps.pathtext
gigoiy Dec 12, 2025
9eb51af
Implemented pytest for new feature
gigoiy Dec 12, 2025
08be6cf
Removed whitespace
gigoiy Dec 12, 2025
28390f6
Fixed coding style
gigoiy Dec 12, 2025
4828055
Further fixed coding style
gigoiy Dec 12, 2025
7a60bcb
Further fixed coding style. Sigh.
gigoiy Dec 12, 2025
723f9f5
Updated backend_ps.py to call the proper function
gigoiy Dec 12, 2025
63af2ce
Added text-as-path functionality to backend_ps.py
gigoiy Dec 9, 2025
6aadb27
Merge branch 'newfeature-for-issue-8480' of https://github.com/gigoiy…
gigoiy Dec 12, 2025
36ebb70
Added pytest for new feature, rebased commits
gigoiy Dec 10, 2025
646cec2
Merge branch 'newfeature-for-issue-8480' of https://github.com/gigoiy…
gigoiy Dec 12, 2025
72a3667
Added text-as-path functionality to backend_ps.py
gigoiy Dec 9, 2025
baac103
Removed trailing whitespace in backend_ps.py
gigoiy Dec 9, 2025
61895b5
Properly implemented the new feature from
gigoiy Dec 10, 2025
4e92344
Fixed coding style
gigoiy Dec 10, 2025
bec5d98
Added pytest for new feature, rebased commits
gigoiy Dec 10, 2025
d462da1
Removed trailing whitespace
gigoiy Dec 10, 2025
988085a
Implemented pytest for new feature
gigoiy Dec 12, 2025
5e6a07d
Removed whitespace
gigoiy Dec 12, 2025
f8e5be1
Fixed coding style
gigoiy Dec 12, 2025
55aa093
Further fixed coding style
gigoiy Dec 12, 2025
714fcf5
Further fixed coding style. Sigh.
gigoiy Dec 12, 2025
ea7f0bc
Updated backend_ps.py to call the proper function
gigoiy Dec 12, 2025
a424f55
Merge branch 'newfeature-for-issue-8480' of https://github.com/gigoiy…
gigoiy Dec 12, 2025
4e80726
FIX: figureoptions updates title string only
rcomer Nov 20, 2025
2668413
Add type annotation for LocationEvent.modifiers (#30841)
NMertsch Dec 12, 2025
ddd097a
Update release docs for new publish workflow, remove old publish step
ksunden Dec 11, 2025
6677d45
Added text-as-path functionality to backend_ps.py
gigoiy Dec 9, 2025
2276e3e
Removed trailing whitespace in backend_ps.py
gigoiy Dec 9, 2025
faf2580
Properly implemented the new feature from
gigoiy Dec 10, 2025
69927fd
Fixed coding style
gigoiy Dec 10, 2025
6c50c6e
Added text-as-path functionality to backend_ps.py
gigoiy Dec 9, 2025
7fe3d35
Added text-as-path functionality to backend_ps.py
gigoiy Dec 9, 2025
7d3bbc3
Merge branch 'newfeature-for-issue-8480' of https://github.com/gigoiy…
gigoiy Dec 12, 2025
063500a
Rebased branch
gigoiy Dec 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 54 additions & 4 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
import matplotlib as mpl
from matplotlib import _api, cbook, _path, _text_helpers
from matplotlib.backend_bases import (
_Backend, FigureCanvasBase, FigureManagerBase, RendererBase)
_Backend, FigureCanvasBase, FigureManagerBase, RendererBase, GraphicsContextBase)
from matplotlib.cbook import is_writable_file_like, file_requires_unicode
from matplotlib.font_manager import get_font
from matplotlib.font_manager import get_font, FontProperties
from matplotlib.ft2font import LoadFlags
from matplotlib._mathtext_data import uni2type1
from matplotlib.path import Path
from matplotlib.texmanager import TexManager
from matplotlib.transforms import Affine2D
from matplotlib.backends.backend_mixed import MixedModeRenderer
from . import _backend_pdf_ps
from matplotlib import textpath


_log = logging.getLogger(__name__)
Expand Down Expand Up @@ -459,6 +460,52 @@
if store:
self.linewidth = linewidth


def _draw_text_as_path(self,

Check warning on line 464 in lib/matplotlib/backends/backend_ps.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Trailing whitespace Raw Output: message:"Trailing whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backends/backend_ps.py" range:{start:{line:464 column:33} end:{line:464 column:34}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W291" url:"https://docs.astral.sh/ruff/rules/trailing-whitespace"} suggestions:{range:{start:{line:464 column:33} end:{line:464 column:34}}}
gc: GraphicsContextBase,

Check warning on line 465 in lib/matplotlib/backends/backend_ps.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Trailing whitespace Raw Output: message:"Trailing whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backends/backend_ps.py" range:{start:{line:465 column:52} end:{line:465 column:53}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W291" url:"https://docs.astral.sh/ruff/rules/trailing-whitespace"} suggestions:{range:{start:{line:465 column:52} end:{line:465 column:53}}}
x,

Check warning on line 466 in lib/matplotlib/backends/backend_ps.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Trailing whitespace Raw Output: message:"Trailing whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backends/backend_ps.py" range:{start:{line:466 column:30} end:{line:466 column:31}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W291" url:"https://docs.astral.sh/ruff/rules/trailing-whitespace"} suggestions:{range:{start:{line:466 column:30} end:{line:466 column:31}}}
y,

Check warning on line 467 in lib/matplotlib/backends/backend_ps.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Trailing whitespace Raw Output: message:"Trailing whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backends/backend_ps.py" range:{start:{line:467 column:30} end:{line:467 column:31}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W291" url:"https://docs.astral.sh/ruff/rules/trailing-whitespace"} suggestions:{range:{start:{line:467 column:30} end:{line:467 column:31}}}
s,

Check warning on line 468 in lib/matplotlib/backends/backend_ps.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Trailing whitespace Raw Output: message:"Trailing whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backends/backend_ps.py" range:{start:{line:468 column:30} end:{line:468 column:31}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W291" url:"https://docs.astral.sh/ruff/rules/trailing-whitespace"} suggestions:{range:{start:{line:468 column:30} end:{line:468 column:31}}}
prop: FontProperties,

Check warning on line 469 in lib/matplotlib/backends/backend_ps.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Trailing whitespace Raw Output: message:"Trailing whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backends/backend_ps.py" range:{start:{line:469 column:49} end:{line:469 column:50}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W291" url:"https://docs.astral.sh/ruff/rules/trailing-whitespace"} suggestions:{range:{start:{line:469 column:49} end:{line:469 column:50}}}
angle,

Check warning on line 470 in lib/matplotlib/backends/backend_ps.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Trailing whitespace Raw Output: message:"Trailing whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backends/backend_ps.py" range:{start:{line:470 column:34} end:{line:470 column:35}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W291" url:"https://docs.astral.sh/ruff/rules/trailing-whitespace"} suggestions:{range:{start:{line:470 column:34} end:{line:470 column:35}}}
ismath=False):
# Get path data from text2path
tp = textpath.TextToPath()
# Handle math text
verts, codes = tp.get_text_path(prop, s, ismath=ismath)
# Create Path object
path = Path(verts, codes)
# Create transformation
transform = Affine2D().translate(x, y).rotate_deg(angle)
# Scale to correct size (text2path returns units that need scaling)
fontsize = prop.get_size()
unitsperem = 1000.0
scale = fontsize / unitsperem
transform.scale(scale, scale)

def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
# Get path data from text2path
if ismath:
# Handle math text
verts, codes = self._text2path.get_text_path(prop, s, ismath=True)
else:
# Handle regular text
verts, codes = self._text2path.get_text_path(prop, s, ismath=False)

Check warning on line 494 in lib/matplotlib/backends/backend_ps.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Blank line contains whitespace Raw Output: message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backends/backend_ps.py" range:{start:{line:494 column:1} end:{line:494 column:5}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W293" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:494 column:1} end:{line:494 column:5}}}
# Create Path object
path = Path(verts, codes)

Check warning on line 497 in lib/matplotlib/backends/backend_ps.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Blank line contains whitespace Raw Output: message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backends/backend_ps.py" range:{start:{line:497 column:1} end:{line:497 column:5}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W293" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:497 column:1} end:{line:497 column:5}}}
# Create transformation
transform = Affine2D().translate(x, y).rotate_deg(angle)

Check warning on line 500 in lib/matplotlib/backends/backend_ps.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Blank line contains whitespace Raw Output: message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backends/backend_ps.py" range:{start:{line:500 column:1} end:{line:500 column:5}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W293" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:500 column:1} end:{line:500 column:5}}}
# Scale to correct size (text2path returns units that need scaling)
fontsize = prop.get_size_in_points()
scale = fontsize / self._text2path.FONT_SCALE
transform.scale(scale, scale)

# Draw the path
self.draw_path(gc, path, transform, rgbFace=gc.get_rgb())

@staticmethod
def _linejoin_cmd(linejoin):
# Support for directly passing integer values is for backcompat.
Expand Down Expand Up @@ -765,14 +812,17 @@
if self._is_transparent(gc.get_rgb()):
return # Special handling for fully transparent.

if ismath == 'TeX':
if ismath == 'TeX' and not mpl.rcParams['ps.pathtext']:
return self.draw_tex(gc, x, y, s, prop, angle)

if ismath:
if ismath and not mpl.rcParams['ps.pathtext']:
return self.draw_mathtext(gc, x, y, s, prop, angle)

stream = [] # list of (ps_name, x, char_name)

if mpl.rcParams['ps.pathtext']:
return self._draw_text_as_path(gc, x, y, s, prop, angle, ismath=False)

if mpl.rcParams['ps.useafm']:
font = self._get_font_afm(prop)
ps_name = (font.postscript_name.encode("ascii", "replace")
Expand Down
47 changes: 47 additions & 0 deletions lib/matplotlib/generate_pstext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import matplotlib.pyplot as plt

plt.rcParams['ps.pathtext'] = True
fig, ax = plt.subplots()
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> a424f555d13ebadbb6089ecca939ea831ddd2d40
ax.set_xlabel('Testing X')
ax.set_ylabel('Testing Y')
=======
>>>>>>> 9eb51af777 (Implemented pytest for new feature)

Check failure on line 17 in lib/matplotlib/generate_pstext.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] reported by reviewdog 🐶 Invalid decimal literal [syntax] Raw Output: lib/matplotlib/generate_pstext.py:17: error: Invalid decimal literal [syntax]
=======
ax.set_xlabel('Testing X')
ax.set_ylabel('Testing Y')
>>>>>>> 723f9f5931 (Updated backend_ps.py to call the proper function)
=======
ax.set_xlabel('Testing X')
ax.set_ylabel('Testing Y')
<<<<<<< HEAD
>>>>>>> 36ebb70f4c (Added pytest for new feature, rebased commits)
=======
ax.set_xlabel('Testing X')
ax.set_ylabel('Testing Y')
>>>>>>> 63af2cefba (Added text-as-path functionality to backend_ps.py)
=======
>>>>>>> 9eb51af777 (Implemented pytest for new feature)
=======
ax.set_xlabel('Testing X')
ax.set_ylabel('Testing Y')
>>>>>>> 723f9f5931 (Updated backend_ps.py to call the proper function)
=======
>>>>>>> 646cec28d9ed402921f628deedd345a58b588a9a
>>>>>>> a424f555d13ebadbb6089ecca939ea831ddd2d40
ax.text(0.25, 0.25, 'c')
ax.text(0.25, 0.5, 'a')
ax.text(0.25, 0.75, 'x')
fig.savefig(
'C:/Users/kbele/Documents/matplotlib-dev/lib/matplotlib/tests/baseline_images/test_pathtext/text_as_path.eps',
format='eps'
)
plt.rcParams['ps.pathtext'] = False
1 change: 1 addition & 0 deletions lib/matplotlib/mpl-data/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@
# Experimental: may produce smaller files.
# xpdf intended for production of publication quality files,
# but requires ghostscript, xpdf and ps2eps
#ps.pathtext: False # Enable or Disable drawing text as a path
#ps.distiller.res: 6000 # dpi
#ps.fonttype: 3 # Output Type 3 (Type3) or Type 42 (TrueType)

Expand Down
25 changes: 25 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,31 @@ def _convert_validator_spec(key, conv):
"ps.useafm": validate_bool,
# use ghostscript or xpdf to distill ps output
"ps.usedistiller": validate_ps_distiller,
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
"ps.pathtext": validate_bool, # enables text-to-vector image
=======
"ps.pathtext": validate_bool, # enables text-to-vector image
>>>>>>> c13f88acb3 (Properly implemented the new feature from)
=======
"ps.pathtext": validate_bool, # enables text-to-vector image
>>>>>>> 7819eadefd (Fixed coding style)
=======
"ps.pathtext": validate_bool, # enables text-to-vector image
>>>>>>> 36ebb70f4c (Added pytest for new feature, rebased commits)
=======
"ps.pathtext": validate_bool, # enables text-to-vector image
>>>>>>> 63af2cefba (Added text-as-path functionality to backend_ps.py)
=======
"ps.pathtext": validate_bool, # enables text-to-vector image
>>>>>>> dd02737ba2 (Removed trailing whitespace)
=======
"ps.pathtext": validate_bool, # enables text-to-vector image
>>>>>>> a424f555d13ebadbb6089ecca939ea831ddd2d40
"ps.distiller.res": validate_int, # dpi
"ps.fonttype": validate_fonttype, # 3 (Type3) or 42 (Truetype)
"pdf.compression": validate_int, # 0-9 compression level; 0 to disable
Expand Down
Loading
Loading