Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
burghoff committed Jul 12, 2024
1 parent 0826654 commit e974cd2
Show file tree
Hide file tree
Showing 15 changed files with 3,373 additions and 16 deletions.
27 changes: 17 additions & 10 deletions scientific_inkscape/dhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@
inkex.Style = styles0.Style0

# Next we make sure we have the text submodule
sys.path.append(
os.path.join(si_dir, inkex_to_use, "site-packages", "python_fontconfig")
)
import inkex.text # noqa
import speedups # noqa
import speedups # noqa

from inkex import Style
from inkex.text.cache import BaseElementCache
Expand Down Expand Up @@ -126,15 +129,18 @@ def count_callers():
match = re.search(r'__version__\s*=\s*"(.*?)"', content)
vstr = match.group(1) if match else "1.0.0"
inkex.installed_ivp = inkex.vparse(vstr) # type: ignore
inkex.installed_haspages = inkex.installed_ivp[0]>=1 and inkex.installed_ivp[1]>=2
inkex.installed_haspages = inkex.installed_ivp[0] >= 1 and inkex.installed_ivp[1] >= 2

# On v1.1 gi produces an error for some reason that is actually fine
import platform
if platform.system().lower() == "windows" and inkex.installed_ivp[0:2]==[1, 1]:

if platform.system().lower() == "windows" and inkex.installed_ivp[0:2] == [1, 1]:
if inkex.text.font_properties.HASPANGOFT2:
from gi.repository import GLib

def custom_log_writer(log_domain, log_level, message, user_data):
return GLib.LogWriterOutput.UNHANDLED

GLib.log_set_writer_func(custom_log_writer, None)


Expand Down Expand Up @@ -940,12 +946,12 @@ def global_transform(el, trnsfrm, irange=None, trange=None, preserveStroke=True)
if preserveStroke:
if sw is not None:
neww, sf, _ = composed_width(el, "stroke-width")
if sf!=0:
if sf != 0:
el.cstyle["stroke-width"] = str(sw / sf)
# fix width
if not (sd in [None, "none"]):
nd, sf = composed_list(el, "stroke-dasharray")
if sf!=0:
if sf != 0:
el.cstyle["stroke-dasharray"] = (
str([sdv / sf for sdv in sd]).strip("[").strip("]")
)
Expand Down Expand Up @@ -1130,7 +1136,6 @@ def si_tmp(dirbase="", filename=None):
return subdir_path



ttags = tags((inkex.TextElement, inkex.FlowRoot))
line_tag = inkex.Line.ctag
cpath_support_tags = tags(BaseElementCache.cpath_support)
Expand All @@ -1144,7 +1149,8 @@ def si_tmp(dirbase="", filename=None):
inkex.Symbol,
)
)
grouplike_tags.add(mask_tag)
grouplike_tags.add(mask_tag)


def bounding_box2(
self, dotransform=True, includestroke=True, roughpath=False, parsed=False
Expand Down Expand Up @@ -1197,9 +1203,7 @@ def bounding_box2(
)
else:
anyarc = any(s.letter in ["a", "A"] for s in pth)
pth = (
inkex.Path(inkex.CubicSuperPath(pth)) if anyarc else pth
)
pth = inkex.Path(inkex.CubicSuperPath(pth)) if anyarc else pth
pts = list(pth.control_points)
x = [p.x for p in pts]
y = [p.y for p in pts]
Expand Down Expand Up @@ -1270,11 +1274,13 @@ def bounding_box2(
self._cbbox[(dotransform, includestroke, roughpath, parsed)] = ret
return self._cbbox[(dotransform, includestroke, roughpath, parsed)]


def set_cbbox(self, val):
"""Invalidates the cached bounding box."""
if val is None and hasattr(self, "_cbbox"):
delattr(self, "_cbbox")


inkex.BaseElement.cbbox = property(bounding_box2, set_cbbox)
inkex.BaseElement.bounding_box2 = bounding_box2

Expand Down Expand Up @@ -1630,6 +1636,7 @@ def character_fixer(els):
spantags = tags((Tspan, inkex.FlowPara, inkex.FlowSpan))
TEtag = inkex.TextElement.ctag


def replace_non_ascii_font(elem, newfont, *args):
"""Replaces non-ASCII characters in an element with a specified font."""

Expand Down
2 changes: 1 addition & 1 deletion scientific_inkscape/inkex1_3_0/inkex/text/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import inkex
from inkex import Style
from inkex import BaseElement, SvgDocumentElement
from text.utils import shapetags, tags, ipx, list2
from text.utils import shapetags, tags, ipx, list2 # pylint: disable=import-error
import lxml

EBget = lxml.etree.ElementBase.get
Expand Down
8 changes: 3 additions & 5 deletions scientific_inkscape/inkex1_3_0/inkex/text/font_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ def custom_load_library(name):


with patch("ctypes.cdll.LoadLibrary", side_effect=custom_load_library):
try:
import fontconfig as fc
except ModuleNotFoundError:
import inkex.text.packages.python_fontconfig.fontconfig as fc # type: ignore
import fontconfig as fc # pylint: disable=import-error

FC = fc.FC


Expand Down Expand Up @@ -1172,7 +1170,7 @@ class Conversions:
}


C = Conversions
C = Conversions # pylint: disable=invalid-name


def inkscape_spec_to_css(fstr, usepango=False):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/__pycache__/
/build/
Loading

0 comments on commit e974cd2

Please sign in to comment.