GhostScript - wrong font substitution (wrong characters) - linux

I'm trying to convert pdf file to image.
Command: gs -sDEVICE=pngalpha -sOutputFile=cover.png -r144 myfile.pdf
Output:
Can't find CID font "MyStrangeNonEmbeddedFont".
Attempting to substitute CID font /Adobe-Identity for /MyStrangeNonEmbeddedFont, see doc/Use.htm#CIDFontSubstitution.
The substitute CID font "Adobe-Identity" is not provided either. attempting to use fallback CIDFont.See doc/Use.htm#CIDFontSubstitution.
Loading a TT font from /some/path/DroidSansFallback.ttf to emulate a CID font Adobe-Identity ... Done.
Font is successfully substituted with DroidSansFallback.ttf, but all characters are incorrect. Examples:
'C' is substituted with '<'
'6' is substituted with '>'
'B' is substituted with '#'
'D' is substituted with 'B'
Is it possible to fix it?

Too long for a comment, added as an answer instead.
This is why the PDF specification strongly suggests embedding CIDFonts.
Character code -> CID -> Glyph description is a complex area of the specification, more so than for regular fonts.
The only way you are going to get this correct is to use the original font that was not embedded. Your best bet to 'fix' this is to embed the font and make a new PDF file.
If you can't do that then you can source the font and add a specific entry to cidfmap.
Failing that then you can try editing the CMap in the PDF file (the CMap maps character codes to CIDs) or the character codes in the document, to match whatever font you have available (this is likely to be a lot of work).
The Ordering of the CIDSystemInfo 'might' give you some clues, you may be able to use the Registry and Ordering to determine how CIDs relate to actual glyphs.
If you have a genuine CIDFont to use as a substitute might be able to manipulate the CIDs of the glyphs, but that will be hard. If you are using a TrueType font as a substitute fro a CIDFont then you can't alter the CMap which Ghostscript will produce for that CIDFont.

Related

Is there some way to get Unicode symbols to be fixed-width in a fixed-width font?

I have made a webpage which uses a <pre> block to display text with a monospace font. I've tried the default font, as well as a bunch of ones such as "Fixedsys" or "Courier New", etc. The same result happens no matter what I do:
This is what it looks like if I use a Unicode checkmark: https://i.stack.imgur.com/Dyocg.png
This is what it looks like if I instead use a "X": https://i.stack.imgur.com/VxvRj.png
It seems as if various Unicode symbols do not respect the fixed width that each character is supposed to have with "monospace" or "fixed-width character" fonts.
I don't want to use "X" instead of the checkmark because it looks very ugly. But on the other hand, it also looks very ugly when the "columns" don't line up...
Is there anything I can do about this
Please check what fonts are actually used by the browser. For Chrome, refer to: https://makandracards.com/makandra/59967-css-how-to-find-out-the-rendered-font-in-chrome.
Two sollutions come to mind:
Find a monospaced font that supports the symbols you want to use. You might want to check you my answer here: https://stackoverflow.com/a/73313342/13663706
Apply the letter-spacing (https://developer.mozilla.org/en-US/docs/Web/CSS/letter-spacing) to your symbol to compensate for the 'wrong' width.

Eps to svg, special character not converted

I'm trying to convert an eps (created with Mathtype) to svg format.
I don't have any problems with math characteres, but I'm unable to get any special characters (aka àâä...)
I have tried on unix and windows, and none of those works.
The font used is Arial, and is installed properly(Default on Windows, manually added in fonts folder in unix)
I have oppened the Arial font in windows font manager and the non working character are in.
They just aren't converted.
Actually, to convert I use Inkscape (with ghostscript) like this :
inkscape -z -f in.eps -l out.svg
Thanks in advance,
Edit :
Added in.eps file
https://pastebin.com/vBtUVy69
The fact that you have installed Arial on your Windows box has little to do with the problem.
Does the EPS file include the embedded Arial font ? If not then you are dependent on font substitution. You should probably post a sample EPS file so that we can look at it.
My guess is that the Arial font is not embedded, so Ghostscript substittues Helvetica, and the Helvetica font doesn't have those glyphs, or they are not encoded at the character codes which the EPS file thinks they are.
[EDIT]
The EPS comments say DocumentNeededFonts: Arial-BoldMT", so the EPS does not include the font and you get font substitution.
I can't tell you immediately why the SVG says Arial. I can guess, but in the absence of a complete description as to how you are producing the SVG I can't (obviously) be sure.
Now... if the conversion path uses Ghostscript's pdfwrite device to create a PDF file from the EPS, and that PDF file is then somehow converted to Inkscape's internal format (or directly to SVG using something other than Ghostscript) then what is happening is that Ghostscript is substituting Helvetica for the missing Arial-BoldMT and when it produces the PDF file it embeds the Helvetica font, but calls it Arial-BoldMT (or whatever). That's a consequence of the font substitution, the font that gets substituted gets renamed to the expected name.
I think you can avoid that by setting -dEmbedAllFonts to false, though I haven't tested it. Even if you do, all that happens is that the PDF file then doesn't have the font, just the same as the EPS file. So the SVG creation will (presumably) have to use a substitute font instead. All you do is shove the problem further down.
The correct answer to this is 'always embed fonts'.
You can also make the Arial-BoldMT font available to Ghostscript by editing its fontmap.GS file in ghostpdl/Resource/Init for builds where the resources are not built into a ROM file system. For builds which do use a ROM file system (eg Windows) you must pick up a copy of the Resources (from the Ghostscript Git repository), modify the fontmap.GS file and then tell Ghostscript to use the modified resources by pointing to it with the -I switch.
This is still a hack, because its a TrueType font being used as a replacement for a PostScript font, so there's a certain amount of guesswork going on inside Ghostscript, but it usually works well enough, YMMV.

Font name of a specific character in a string | Swift

is it possible to get the font name and its size of a specific character in string in Swift?
I want to make a textview in which you can type with different fonts. I did this, but the problem is for example if something, lets say "hello" is written in Helvetica 16pt, and my current font Helvetica 24 pt, and then I want to write something more in "hello", let say "helloworld". This is possible in swift using attributed strings, but the word "hello" will be 16pt, and the word "world", will be 24pt. So, how to detect the font of the "hello" word, and then change the font automatically, and continue typing with the same font?
You should have a look at the NSAttributedString documentation. The font size attribute you mentioned is actually contained within the NSFontAttributeName key, which stores an NSFont which has both font type and size. You can directly access that using fontAttributesInRange: if you know where you want to look in the string.

Specifying alternate glyphs for potentially unrepresented unicode code point

Unicode has a lot of fancy code points that can be used to do things like change the direction text is formatted, include inband protocol information and other things.
I want to find out if there is a way of specifying, as part of a unicode string, a 'fallback' glyph or set of glyphs where an uncommon unicode code point is unrepresented in the font being used to display the text?
Example:
"æ<character to signify use following as alternate if previous character unavailable>ae<character to specify end of alternate>"
I've had a look through some of these code points at unicode.org and tried some different searches on SO without success. Some of the topics I've looked at:
Is there a way to programatically determine if a font file has a specific Unicode Glyph? (Windows/C#)
How to map code points to unicode characters depending on the font used? (Java)

MailMerge: No fixed width font?

I am trying to send data to a specific MergeField. The data are sent correctly. Each line of the data has for specific characters. For example the data to the field may be:
12345 FIRST\nABCDE.F SECOND
(it cannot get the newline so i just so it through character \n)
Now in the printed document each character has its one width, '1' is smaller than 'E' for example. So the data are not alligned within the field. I tried the following fonts: Arial, Tahoma, Courier New. Nothing helped.
Any ideas? Thanks in advance.
Ps the data are sent through an executable built by Visual C++ 5.0!!
You should probably use a tab-stop based layout. Set your tab-stops every, say, centimetre or so (i.e. just big than the widest character in your font) and add a tab before each element that needs to be aligned.
With this you shouldn't need to find a fixed width font and can use something more attractive.
Edit: Out of interest, I wonder why you have no luck with Courier New which is fixed width.
Maybe you could post a screenshot somewhere so we can have a look at your problem in more detail.
Try Courier - it does not have kerning (kerning = variable character width)
Also in the Font window there is a check box that allows you to apply kerning to fonts of a certain size or above - setting this value to a large font size may remove kerning.

Resources