-
Notifications
You must be signed in to change notification settings - Fork 2k
Images as svg #1288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Images as svg #1288
Conversation
FTR, here is the xslt stylesheet (not clean): <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:svg="http://www.w3.org/2000/svg">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()" mode="center">
<xsl:param name="center_val"/>
<xsl:copy>
<xsl:apply-templates select="@* | node()" mode="center">
<xsl:with-param name="center_val"><xsl:value-of select="$center_val"/></xsl:with-param>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@*" mode="center">
<xsl:param name="center_val"/>
<xsl:copy>
<xsl:apply-templates select="@* | node()" mode="center">
<xsl:with-param name="center_val"><xsl:value-of select="$center_val"/></xsl:with-param>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="svg:g[svg:rect]">
<xsl:copy>
<xsl:apply-templates select="@* | node()" mode="center">
<xsl:with-param name="center_val">
<xsl:value-of select="svg:rect/@width div 2"/>
</xsl:with-param>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="svg:g[svg:rect]" mode="center">
<xsl:copy>
<xsl:apply-templates select="@* | node()" mode="center">
<xsl:with-param name="center_val">
<xsl:value-of select="svg:rect/@width div 2"/>
</xsl:with-param>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="svg:tspan" mode="center">
<xsl:param name="center_val"/>
<xsl:copy>
<xsl:attribute name="x"><xsl:value-of select="$center_val"/></xsl:attribute>
<xsl:apply-templates select="@y | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="svg:text" mode="center">
<xsl:param name="center_val"/>
<xsl:copy>
<xsl:attribute name="stroke"><xsl:choose><xsl:when test="@stroke"><xsl:value-of select="@stroke"/></xsl:when><xsl:otherwise>#979797</xsl:otherwise></xsl:choose></xsl:attribute>
<xsl:attribute name="stroke-width">0</xsl:attribute>
<xsl:attribute name="font-family">Source Code Pro</xsl:attribute>
<xsl:attribute name="font-size">12px</xsl:attribute>
<xsl:attribute name="font-weight">900</xsl:attribute>
<xsl:attribute name="fill"><xsl:choose><xsl:when test="@stroke"><xsl:value-of select="@stroke"/></xsl:when><xsl:otherwise>#979797</xsl:otherwise></xsl:choose></xsl:attribute>
<xsl:attribute name="fill-opacity">1</xsl:attribute>
<xsl:attribute name="stroke-width">0</xsl:attribute>
<xsl:attribute name="text-anchor">middle</xsl:attribute>
<xsl:apply-templates select="@id | node()" mode="center">
<xsl:with-param name="center_val">
<xsl:value-of select="$center_val"/>
</xsl:with-param>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet> |
I've only had a closer look at
Don't change the value of The text is not vertically centered, so the descenders of the characters (lowercase g, j, y, etc.) are not within the grey area. I cannot name the exact values for the positions (x=... and y=...). The values I also came up with another effect. |
Unfortunately, this cannot be done automatically by script. Some final hand polishing will inevitably be needed, typically for SVGs that are not just an assembly of text boxes. For this one, I think that the export to SVG yields bad results: the size of the arrow heads is wrong. Changing the font family in batch can still be performed.
OK, I will tweak the script a little more.
This may be an issue, because this font is not present on the git-scm.com web server and we don't want to include it into our PDFs (we use Noto to be sure that we cover all character sets). As the SVG may be translated, it would be safer to use a font for which we have a wide range of symbols available. Remember Progit is translated in quite a number of languages. For Ebooks, I'm not sure, but I think we cannot impose a font. Would it be too bad to use Noto here? |
I've never seen this font before. Do you have a link, so that we can be sure to talk about the same font? |
It's Google's "No Tofu" font: |
This font is even less suitable than the former "Menlo Mono" font. It has only one (normal) font-weight. In the picture you can see the 12 different samples of the "Source Code Pro". I installed the "Noto" here – as far as I can see the character-set is equal to the "Source Code Pro", which contains 2.030 characters. Last not least the "Noto" font is in TTF format. Is there no way to install this font on the server? Useful hints may be found here.. |
I don't see the same thing for Noto: https://www.google.com/get/noto/#sans-lgc where there are multiple font-weights, with different condensed forms.
in Sans and Serif forms. Where did you get the Noto font? The ones available on the site are pretty complete. If you download the complete set, that's 1.1GB! |
You have linked to Noto Sans and not to Noto Mono. Inside your selection, there is Noto Mono (1 style) mono spaced only. Compare the width of the letter "i" with the width of the letter "M". With monospaced fonts, the two letters occupy the same space. With propotional fonts, the distance between two letters is optically balanced with so-called "hints", so that the space occupied by a "M" is larger than that of an "i". Reading texts using proportional fonts is more comfortable. A mono spaced font is requested by Ben. On the Google Fonts page you will find the following selection. No single type is heavier than bold. |
I'm not sure this is a strong requirement. As I already said, mono fonts don't have extended charsets, so they cannot be used in translation context. |
The Menlo Mono is monospaced and was used before in PNG diagrams. EDIT In vector drawing programs there is a function called "Convert To Paths" or something similar. This function converts letters into shapes. Texts are then no longer easy to edit, but the drawing can then be displayed on any computer, regardless of which fonts are installed. I always thought a proportional font in this place to be a better choice. Since I don't understand enough about coding, I followed Ben's argument:
You would have to decide if monospaced is a MUST or if a proportional font is possible. Regardless of that, I vote for a font in OTF format that offers better features. |
I'm with you here. This is what the original Sketch export to PNG yielded: When I open the file in Sketch now, the arrow bodies are narrower, and the heads are wider, and it's pretty bad. It might be possible to fix this with a script, but it also might be just a manual slog. Also notable: most of the text in boxes should be white, but it all exported as grey for some reason.
As we discussed before though, most of the text in the diagrams is ref names and sha-1 hashes, which don't necessarily need to be translated. What explanatory text there is could easily be set in a different font if Source Code Pro doesn't work for a particular translation project. My bottom line here is: just convert everything to Source Code Pro. This PR should be a high-level pass at automated fixes, we can hash out the smaller differences in later PRs. We're not trying to make perfect diagrams with this patch, we're just trying to get closer. |
That's quite easy to fix with Inkscape.
The reason is the wrong value of
Some minutes ago I edited my previous post again. I show a work-around to be independent of the installed fonts and still be able to use the advantages of SVG graphics (See). |
I agree that using a monospace font is a widely accepted typographical convention to refer to "source code" things, by contrast with English text. They don't need to be translated. So, the next question is how to embed them into our artifacts. For the other parts of text, let's just stick to a Noto Sans, which is already available. As for the script, I'm just going to convert every fonts to "Source Code Pro", and change the stroke to none in every text elements. @max123kl changing fonts to paths will make the files much larger, I'd prefer a solution where we embed the necessary stuff. Plus, once it's converted there's no way back to edition, so this is a kind of compilation. |
@ben SO Which colors should be displayed in the future? I'm asking because I' m currently building the symbols for Inkscape. Created a PR #1289 |
Ah... The images on git-scm are static and they may have not been updated for a while. There were also a few commits in order to reduce their size for faster and lighter delivery. It may have brought a quality regression. In the book, the images are still the png. |
No source code has been changed to pull in the new SVGs. We'd have to change a line like this one: image::images/lifecycle.png[The lifecycle of the status of your files.] …to refer instead to |
I have here a backup file of progit2.pdf (downloaded on 2019-07-11), where the images are more blurry than the download from 2019-08-09. |
They may be the first PNG files after changing the font to Roboto Mono. |
commit 89522c6 might be the culprit |
✨ |
No description provided.