* SVG text alignment issue @ 2022-06-28 6:07 Thangalin via ntg-context 2022-06-29 2:35 ` Aditya Mahajan via ntg-context 0 siblings, 1 reply; 7+ messages in thread From: Thangalin via ntg-context @ 2022-06-28 6:07 UTC (permalink / raw) To: mailing list for ConTeXt users; +Cc: Thangalin [-- Attachment #1.1: Type: text/plain, Size: 1365 bytes --] In the following example, the line and text should be aligned to the middle when LMTX converts the SVG figure using MP. (Note that you may have to install Roboto, but the font isn't the issue.) % SOF \startbuffer[svg] <svg width="25mm" height="70mm" viewBox="0 0 25 70" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <path d="m 12.500001,63.971412 v -12.4787" id="path2" style="fill:none;fill-opacity:1;stroke:#000000;stroke-opacity:1" /> <text x="-48.831322" y="15.60547" id="text4933-8-6" transform="rotate(-90)" style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;font-family:Roboto;-inkscape-font-specification:'Roboto, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal"><tspan id="tspan159594-1" x="-48.831322" y="15.60547" style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;font-family:Roboto;-inkscape-font-specification:'Roboto, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal">16p13.3</tspan></text> </svg> \stopbuffer \starttext \placefigure[]{}{\includesvgbuffer[svg][conversion=mp]} \stoptext % EOF [-- Attachment #1.2: Type: text/html, Size: 2086 bytes --] [-- Attachment #2: Type: text/plain, Size: 493 bytes --] ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: SVG text alignment issue 2022-06-28 6:07 SVG text alignment issue Thangalin via ntg-context @ 2022-06-29 2:35 ` Aditya Mahajan via ntg-context 2022-06-29 4:55 ` Thangalin via ntg-context 2022-06-29 7:03 ` Hans Hagen via ntg-context 0 siblings, 2 replies; 7+ messages in thread From: Aditya Mahajan via ntg-context @ 2022-06-29 2:35 UTC (permalink / raw) To: Thangalin via ntg-context; +Cc: Aditya Mahajan On Mon, 27 Jun 2022, Thangalin via ntg-context wrote: > In the following example, the line and text should be aligned to the > middle when LMTX converts the SVG figure using MP. (Note that you may have > to install Roboto, but the font isn't the issue.) > > % SOF > \startbuffer[svg] > <svg > width="25mm" > height="70mm" > viewBox="0 0 25 70" > xmlns="http://www.w3.org/2000/svg" > xmlns:svg="http://www.w3.org/2000/svg"> > <path > d="m 12.500001,63.971412 v -12.4787" > id="path2" > style="fill:none;fill-opacity:1;stroke:#000000;stroke-opacity:1" /> > <text > x="-48.831322" > y="15.60547" > id="text4933-8-6" > transform="rotate(-90)" > > style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;font-family:Roboto;-inkscape-font-specification:'Roboto, > Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal"><tspan > id="tspan159594-1" > x="-48.831322" > y="15.60547" > > style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;font-family:Roboto;-inkscape-font-specification:'Roboto, > Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal">16p13.3</tspan></text> > </svg> > \stopbuffer > > \starttext > \placefigure[]{}{\includesvgbuffer[svg][conversion=mp]} > \stoptext > % EOF This has nothing to do with SVG. Looking at the definition of \includesvgbuffer, here is a simpler example illustrating the issue: \starttext \startplacefigure[location=here, title={Test}] \dontleavehmode\begingroup \startMPcode draw fullcircle scaled 2cm; \stopMPcode\endgroup \stopplacefigure \stoptext One way to "fix" the alignment is to wrap everything in an hbox: \placefigure[]{}{\hbox{\includesvgbuffer[svg][conversion=mp]}} Maybe there is a simple way to modify the definition of includesvgbuffer so that an \hbox is not needed. Aditya ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: SVG text alignment issue 2022-06-29 2:35 ` Aditya Mahajan via ntg-context @ 2022-06-29 4:55 ` Thangalin via ntg-context 2022-06-29 7:03 ` Hans Hagen via ntg-context 1 sibling, 0 replies; 7+ messages in thread From: Thangalin via ntg-context @ 2022-06-29 4:55 UTC (permalink / raw) To: Aditya Mahajan; +Cc: Thangalin, Thangalin via ntg-context [-- Attachment #1.1: Type: text/plain, Size: 889 bytes --] Thanks Aditya, I tried your suggestion, but the result is the same. Here's the XML setup for all images in the document: \startxmlsetups xml:img \starttexcode \placefloat[here,force]{}{% \hbox{\externalfigure[\xmlatt{#1}{src}][conversion=mp]} } \stoptexcode \stopxmlsetups Here's the Markdown source document: ![](dna-02) The source document is automatically exported as XHTML: <p> <img alt="" src="/path/to/images/dna-02.svg"/> </p> The XHTML is then passed to ConTeXt, whereupon the XML setup for images is applied. The result is the same: the alignment for the text is off. Here's an example where you can see the issue on the 16q24.3 text (far right): https://i.ibb.co/WGh03Sr/genes.png When the same SVG file is rendered using Apache Batik, the white text is aligned to the middle of the black box. Are there aAny other work-arounds? Thank you! [-- Attachment #1.2: Type: text/html, Size: 2412 bytes --] [-- Attachment #2: Type: text/plain, Size: 493 bytes --] ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: SVG text alignment issue 2022-06-29 2:35 ` Aditya Mahajan via ntg-context 2022-06-29 4:55 ` Thangalin via ntg-context @ 2022-06-29 7:03 ` Hans Hagen via ntg-context 2022-06-29 18:48 ` Thangalin via ntg-context 1 sibling, 1 reply; 7+ messages in thread From: Hans Hagen via ntg-context @ 2022-06-29 7:03 UTC (permalink / raw) To: Aditya Mahajan via ntg-context; +Cc: Hans Hagen On 6/29/2022 4:35 AM, Aditya Mahajan via ntg-context wrote: > On Mon, 27 Jun 2022, Thangalin via ntg-context wrote: > >> In the following example, the line and text should be aligned to the >> middle when LMTX converts the SVG figure using MP. (Note that you may have >> to install Roboto, but the font isn't the issue.) >> >> % SOF >> \startbuffer[svg] >> <svg >> width="25mm" >> height="70mm" >> viewBox="0 0 25 70" >> xmlns="http://www.w3.org/2000/svg" >> xmlns:svg="http://www.w3.org/2000/svg"> >> <path >> d="m 12.500001,63.971412 v -12.4787" >> id="path2" >> style="fill:none;fill-opacity:1;stroke:#000000;stroke-opacity:1" /> >> <text >> x="-48.831322" >> y="15.60547" >> id="text4933-8-6" >> transform="rotate(-90)" >> >> style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;font-family:Roboto;-inkscape-font-specification:'Roboto, >> Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal"><tspan >> id="tspan159594-1" >> x="-48.831322" >> y="15.60547" >> >> style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;font-family:Roboto;-inkscape-font-specification:'Roboto, >> Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal">16p13.3</tspan></text> >> </svg> >> \stopbuffer >> >> \starttext >> \placefigure[]{}{\includesvgbuffer[svg][conversion=mp]} >> \stoptext >> % EOF > > This has nothing to do with SVG. Looking at the definition of \includesvgbuffer, here is a simpler example illustrating the issue: > > \starttext > \startplacefigure[location=here, title={Test}] > \dontleavehmode\begingroup > \startMPcode > draw fullcircle scaled 2cm; > \stopMPcode\endgroup > \stopplacefigure > \stoptext > > One way to "fix" the alignment is to wrap everything in an hbox: > > > \placefigure[]{}{\hbox{\includesvgbuffer[svg][conversion=mp]}} > > Maybe there is a simple way to modify the definition of includesvgbuffer so that an \hbox is not needed. Thanks for checking it. Can you test with \pushoverloadmode \unprotect \permanent\tolerant\protected\def\includesvgfile[#1]#*[#2]% {\hbox\bgroup % no \dontleavehmode \getdummyparameters[\c!offset=\zeropoint,#2]% \clf_includesvgfile{#1}\dimexpr\dummyparameter\c!offset\relax \egroup} \permanent\tolerant\protected\def\includesvgbuffer[#1]#*[#2]% {\hbox\bgroup % no \dontleavehmode \getdummyparameters[\c!offset=\zeropoint,#2]% \clf_includesvgbuffer{#1}\dimexpr\dummyparameter\c!offset\relax \egroup} \protect \popoverloadmode Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl ----------------------------------------------------------------- ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: SVG text alignment issue 2022-06-29 7:03 ` Hans Hagen via ntg-context @ 2022-06-29 18:48 ` Thangalin via ntg-context 2022-06-29 21:23 ` Hans Hagen via ntg-context 0 siblings, 1 reply; 7+ messages in thread From: Thangalin via ntg-context @ 2022-06-29 18:48 UTC (permalink / raw) To: mailing list for ConTeXt users; +Cc: Thangalin [-- Attachment #1.1: Type: text/plain, Size: 2342 bytes --] Thanks for checking this. Unfortunately, introducing \hbox didn't work; the text is still off-center with respect to the vertical line: https://i.ibb.co/hYGfdgZ/text-align.png For comparison, the SVG file loaded into Inkscape appears similar to: https://i.ibb.co/KF3PBkw/inkscape-alignment.png Note how the text is vertically centered above the vertical line. To me, it looks like the text, after a rotational transform, is being written to the baseline rather than (cap height + descender height) / 2, which seems to be a MetaPost conversion issue? There's another, possibly related issue, which I'll provide in a separate thread. Here's the code: % SOF \pushoverloadmode \unprotect \permanent\tolerant\protected\def\includesvgfile[#1]#*[#2]% {\hbox\bgroup % no \dontleavehmode \getdummyparameters[\c!offset=\zeropoint,#2]% \clf_includesvgfile{#1}\dimexpr\dummyparameter\c!offset\relax \egroup} \permanent\tolerant\protected\def\includesvgbuffer[#1]#*[#2]% {\hbox\bgroup % no \dontleavehmode \getdummyparameters[\c!offset=\zeropoint,#2]% \clf_includesvgbuffer{#1}\dimexpr\dummyparameter\c!offset\relax \egroup} \protect \popoverloadmode \startbuffer[svg] <svg width="25mm" height="70mm" viewBox="0 0 25 70" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <path d="m 12.500001,63.971412 v -12.4787" id="path2" style="fill:none;fill-opacity:1;stroke:#000000;stroke-opacity:1" /> <text x="-48.831322" y="15.60547" id="text4933-8-6" transform="rotate(-90)" style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;font-family:Roboto;-inkscape-font-specification:'Roboto, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal"><tspan id="tspan159594-1" x="-48.831322" y="15.60547" style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;font-family:Roboto;-inkscape-font-specification:'Roboto, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal">16p13.3</tspan></text> </svg> \stopbuffer \starttext \placefigure[]{}{\includesvgbuffer[svg][conversion=mp]} \stoptext % EOF [-- Attachment #1.2: Type: text/html, Size: 3905 bytes --] [-- Attachment #2: Type: text/plain, Size: 493 bytes --] ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: SVG text alignment issue 2022-06-29 18:48 ` Thangalin via ntg-context @ 2022-06-29 21:23 ` Hans Hagen via ntg-context 2022-06-30 2:49 ` Thangalin via ntg-context 0 siblings, 1 reply; 7+ messages in thread From: Hans Hagen via ntg-context @ 2022-06-29 21:23 UTC (permalink / raw) To: mailing list for ConTeXt users; +Cc: Hans Hagen On 6/29/2022 8:48 PM, Thangalin wrote: > To me, it looks like the text, after a rotational transform, is being > written to the baseline rather than (cap height + descender height) / 2, > which seems to be a MetaPost conversion issue? There's another, possibly > related issue, which I'll provide in a separate thread. Where is that rediculous (rather font version sensitive) rule defined? In all test i did so far baseline works ok. Btw, it is sort of baffling what applications spit out when it comes to svg (and exp text). The cod being meant for machines "eyes" only is not really an excuse. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl ----------------------------------------------------------------- ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: SVG text alignment issue 2022-06-29 21:23 ` Hans Hagen via ntg-context @ 2022-06-30 2:49 ` Thangalin via ntg-context 0 siblings, 0 replies; 7+ messages in thread From: Thangalin via ntg-context @ 2022-06-30 2:49 UTC (permalink / raw) To: mailing list for ConTeXt users; +Cc: Thangalin [-- Attachment #1.1: Type: text/plain, Size: 2764 bytes --] Here's the formal rule: https://www.w3.org/TR/SVG11/coords.html#TransformAttribute rotate(<rotate-angle> [<cx> <cy>]), which specifies a rotation by <rotate-angle> degrees about a given point. If optional parameters <cx> and <cy> are not supplied, the rotation is about the origin of the current user coordinate system. The operation corresponds to the matrix [cos(a) sin(a) -sin(a) cos(a) 0 0]. If optional parameters <cx> and <cy> are supplied, the rotation is about the point (cx, cy). The operation represents the equivalent of the following specification: translate(<cx>, <cy>) rotate(<rotate-angle>) translate(-<cx>, -<cy>). It looks like cx/cy, if not present, mean to rotate the text about its origin, which I would take to be width/2 and height/2. They define the rotation matrix as [cos(a) sin(a) -sin(a) cos(a) 0 0], where a is the angle: https://www.w3.org/TR/SVG11/coords.html#RotationDefined It appears as though LMTX is rotating around the baseline, rather than the central point of the text's bounding box. (I thought that (cap height + descender height) / 2 was the middle, but I suppose that wouldn't account for diacritics.) Thanks for looking into this! On Wed, Jun 29, 2022 at 2:24 PM Hans Hagen via ntg-context < ntg-context@ntg.nl> wrote: > On 6/29/2022 8:48 PM, Thangalin wrote: > > > To me, it looks like the text, after a rotational transform, is being > > written to the baseline rather than (cap height + descender height) / 2, > > which seems to be a MetaPost conversion issue? There's another, possibly > > related issue, which I'll provide in a separate thread. > Where is that rediculous (rather font version sensitive) rule defined? > In all test i did so far baseline works ok. > > Btw, it is sort of baffling what applications spit out when it comes to > svg (and exp text). The cod being meant for machines "eyes" only is not > really an excuse. > > Hans > > > ----------------------------------------------------------------- > Hans Hagen | PRAGMA ADE > Ridderstraat 27 | 8061 GH Hasselt | The Netherlands > tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl > ----------------------------------------------------------------- > > ___________________________________________________________________________________ > If your question is of interest to others as well, please add an entry to > the Wiki! > > maillist : ntg-context@ntg.nl / > http://www.ntg.nl/mailman/listinfo/ntg-context > webpage : http://www.pragma-ade.nl / http://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > > ___________________________________________________________________________________ > [-- Attachment #1.2: Type: text/html, Size: 4803 bytes --] [-- Attachment #2: Type: text/plain, Size: 493 bytes --] ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-06-30 2:49 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-06-28 6:07 SVG text alignment issue Thangalin via ntg-context 2022-06-29 2:35 ` Aditya Mahajan via ntg-context 2022-06-29 4:55 ` Thangalin via ntg-context 2022-06-29 7:03 ` Hans Hagen via ntg-context 2022-06-29 18:48 ` Thangalin via ntg-context 2022-06-29 21:23 ` Hans Hagen via ntg-context 2022-06-30 2:49 ` Thangalin via ntg-context
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).