Is it possible to set a specific font in Mayavi instead of the font family? - mayavi

Is it possible to set a specific font in Mayavi instead of the font family?
So far I only found the option
cb.title_text_property.font_family = 'times'
But I would like to use something like
cb.title_text_property.font_name = 'Roboto Light'
Is there maybe a way to reach through to vtkTextProperty?
If the symbolic constant VTK_FONT_FILE is returned by GetFontFamily(),
the string returned by GetFontFile() must be an absolute filepath to a
local FreeType compatible font.

Related

How to remove all text color attributes from a QTextDocument?

I've got a QTextDocument read from an HTML file; given a QString of HTML data named topicFileData, I do topicFileTextDocument.setHtml(topicFileData);. I then want to strip off all of the color information, making the whole document just use the default foreground and background brush. (I do not want to explicitly set the text to be black text on a white background; I want to remove the color information from the document.) (Background info: the reason I need to do this is that there are spans within the document that are erroneously set with a black foreground color, rather than just having no color information set, and that causes those spans to display as black-on-black when my app is running in "dark mode", when Qt changes the default text background brush to be black instead of white.)
Here's what I tried:
QTextCursor tc(&topicFileTextDocument);
tc.select(QTextCursor::Document);
QTextCharFormat noColorFormat;
noColorFormat.clearForeground();
noColorFormat.clearBackground();
tc.mergeCharFormat(noColorFormat);
This does not work, unfortunately; it looks like mergeCharFormat() does not understand that I want the clearForeground() and clearBackground() actions to be merged in to strip off those attributes.
I can do tc.setCharFormat(noColorFormat); instead, of course, and that does strip off the color attributes correctly; but it also obliterates all of the other character format info (font, etc.), which is not acceptable.
So, ideally I'd like to find an API that lets me explicitly remove a given text attribute from a QTextDocument. Alternatively, I guess I need to loop through all the spans of the QTextDocument one by one, get the char format of the current span, remove the color attributes from the format, and set the modified format back onto the span. That would be fine; but I have no idea how to loop over spans in that way. Thanks for any help.
Instead of creating a new instance of QTextCharFormat, update the current format and reapply it on the QTextEdit;
default = QTextCharFormat()
charFormat = self.textCursor().charFormat()
charFormat.setBackground(default.background())
charFormat.setForeground(default.foreground())
self.textCursor().mergeCharFormat(charFormat)
A sub-optimal solution that I have found as a workaround is to actually edit the HTML data string before I create the QTextDocument, using a regex:
topicFileData.replace(QRegularExpression("(;? ?color: ?#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])"), "");
This works for my situation, because all of the colors in my HTML file are set with color: #XXXXXX style attributes that can be stripped out of the HTML itself. This is fragile, however; colors specified in other ways would not be stripped, and if the body text of the HTML document happened to contain text that matched the regex, the regex would modify it and thus corrupt the content of the document. So I don't recommend this solution, and I won't be accepting it. If somebody can offer a better solution that would be preferable.

Getting Font Size of NSAttributed string

I'm trying to get the font size of an NSAttributedString, however, I'm having trouble doing this.
How do you get the font size of an NSAttributedString in objective-c?
An attributed string does not have "a font size". The used font is an attribute, which can vary over the String. Look at your Q: There are two different fonts in one paragraph. (One for the usual text and one for the keywords.)
Therefore you can only ask for the existing attributes (including font) at a specific location. I. e. - attributesAtIndex:effectiveRange: does this job for you. The attribute key for the font is NSFontAttributeName. If yo do not find this key in the attributes dictionary, it is Helvetica(Neue), 12 pt.

Do PDF files generally use "correct" character codes for font glyphs?

Say I have a PDF file that contains one or more embedded fonts. Here's my understanding of how a single character of text is rendered:
First, determine which font the character uses.
Use the font's "cmap," embedded in the PDF, to determine the font's glyph name for the given character. For example, the character '&' in PDF text might map to a glyph that the font internally calls 'ampersand'.
Use the font's "glyf" table to determine the bounding box / drawing instructions for the glyph name.
Here's my question: is a PDF cmap generally consistent? Put another way, if I encounter the character "&" in a PDF, can I be assured that the cmap will always map "&" to the ampersand glyph? Or does some PDF-generation software create its own arbitrary mapping between character codes and glyph names (which would be rather evil and possibly break in-PDF searching and text selection)?
Of course I realize it's possible for the cmap to use an unintuitive mapping -- I guess I'm asking, does this actually happen in the Real World?
My specific use-case is in the world of music fonts. I'm analyzing characters in a PDF to determine which music glyph each one represents (e.g., treble clef, notehead, etc.). I want to know how confident I can be that the combination of font name and character code will always result in the same glyph. For example, if I know the font name is "Opus" and the glyph is "#", can I assume that will always be mapped to the treble clef glyph? Or do I have to analyze the glyph's metrics to make sure it's actually a treble clef?
It differs from one PDF creator to another.
A fairly common method (alas!) is "order encountered", where the first character in the text stream gets mapped to \001, the next to \002 and so on. So the text "Hello" would be encoded as \001\002\003\003\004.
I want to know how confident I can be that the combination of font name and character code will always result in the same glyph.
In a single PDF document, if the same font object is used in different contexts, it will be true -- the mapping is defined inside the font object. If you encounter another font object that uses the same font but it points to another font stream (i.e., the font subset is embedded twice), then it may not be true. Each subset may have an encoding of its own.
Only if the font object contains a /ToUnicode mapping, you can be confident that values map to the correct characters.

How to set google static map font for city town label

I need to set small font size of google static map. So, what are the required parameters to achieve the same thing. Since, i am using the below url to get static map
http://maps.googleapis.com/maps/api/staticmap?center={$randAppPhoto['latitude']},{$randAppPhoto['longitude']}&scale=2&size=700x400&maptype=terrain&markers={$randAppPhoto['latitude']},{$randAppPhoto['longitude']}&zoom=7&format=jpg&sensor=false
where, $randAppPhoto is an array in php which has dynamic lat , long
I don't think it's possible to change the font for the texts on the maps. You can check a list of parameters for setting map styles here.
Changing scale=2 to scale=1 in the URL will make the street name font smaller, if that's what you're trying to do.

Altering an embedded TrueType font so it will be usable by Windows GDI

I am trying to render PDF content to a GDI device context (a 24bit bitmap to be exact). Parsing the PDF stream into PDF objects and rendering the PDF commands from the content dictionary works well, including font rendering.
Embedded fonts are decompressed from their FontFile streams and "loaded" using AddFontMemResourceEx. Now some embedded fonts remove some TrueType tables that are needed by GDI, like the 'name' table. Because of this, I tried to modify the font by parsing the TrueType subset font into it's tables and modify those tables that have data missing / missing tables are regenerated with as correct information as possible.
I use the Microsoft Font Validator tool to see how "correct" the generated font is. I still get a few errors, like for the maxp table the max values are usually too large (it is a subset) or the xAvgCharWidth field does not equal the calculated value of the 'OS/2' table is not correct but this does not stop other embedded fonts to be useable. The fonts embedded using PDFCreator are the ones that are problematic.
Questions:
How can I determine what I need to
change to the font file in order for
GDI to be able to use it?
Are there any other font validation
tools that might give me insight
into what is still wrong with the
fontfile?
If needed: I can make an original fontfile and an altered fontfile available for download somewhere.
What modifications are made so far:
Make sure there is a 'head', 'hhea', 'maxp' and 'OS/2' section.
If we have a symbol font, clear out Panose and Unicode fields in the 'OS/2' section
Fill in correct values for WInAscent/Desc and TypoAsc/Desc if they we're zero.
Fill in acceptable values for super/subscript/underline positions and sizes.
Scan all glyphs that are left en fill in X/Y min/max values in head.
Rebuild the name section with information from the PDF file it came from.
Almost a year late, but I found the answer:
The font kind (symbol or not) should be the same for the 'cmap' table and the 'name' table. So if the cmap has a 3,0,4 cmap (MS, symbol, segment delta coding) and the name table contains 3,1,$0409 (MS, Unicode, enUS) entries, the font will not load.
It looks like the presence of a 'symbol cmap' determines if the font is considered a symbol font by Windows; flags in 'OS/2' don't seem to matter.
So if a font seems correct using 'Microsoft Font Validator', check if the symbol/unicode fields line up in the 'cmap' and 'name' tables.
With AddMemoryFont in GDI+ you can check it's Status for any errors in the memory font, like NotTrueTypeFont for example.
One option for GDI may be to try to load the embedded font into a document/form yourself with TTLoadEmbeddedFont and then check any errors returned from the error messages. The only functions that supply more information than this one are CreateFontPackage/MergeFontPackage, and their error codes, but I do fail to see how they can be used in your situation.
Barring all this, have you had a chance to review PDFCreator's source code (assuming you're using the open source one as opposed to the commercial one)?