Setting a specific font programmatically

Started by Eva, February 14, 2018, 11:19:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Eva

Hello,

Could someone help me and explain how the fontID value (in ShapeSheet cell Character – Font) is determined? Is it based on the template, or can different computers have different fontIDs even when using the same template? For example, is the Arial fontID (number value) always the same in documents, which use the same template? If I put programmatically a style's fontID value to "4" (on my computer 4 = Arial) in a template, is the style font "Arial" in this template on all computers? It seems that even on the same computer the value of Arial fontID varies in different documents (using different templates)?

All help is appreciated!
Br,
Eva

Surrogate

#1
Hi, Eva !

You can also use FONTTOID function !
Font properties in ShapeSheet functions list

Eva

Thank you for quick response :)!
I use now Visio 2016 version. The problem is that I have already made the code, and now I am wondering that is it a problem, although it seems to work right at least on two different computers. But I was wondering how the font number is determined, because in some other drawing (based on other template) the Arial fontID is different. I just don't understand how this goes.

I was also wondering, if the FONTTOID()  is a good way to set the font, is it somehow slower for Visio?

Br,
Eva

Surrogate



Surrogate

I haven't Visual Studio there and great experience in C# :(

this code in VBA works

shp.CellsSRC(visSectionCharacter, 0, visCharacterFont).FormulaU = "Fonttoid(""Arial"")"

Surrogate

May be something like
Cell CellFont = shp.get_CellsSRC((short)VisSectionIndices.visSectionCharacter, 0, (short)VisCellIndices.visCharacterFont);
CellFont.FormulaU = "FONT(""Arial"")";

please try this code

Eva

Yes, I know now that I should have written it differently.
But the question is, that is it a problem that I have written the value "4" instead of  "Fonttoid(\"Arial\")" to the cell, if it always uses the same template?
Does the fontID remain always the same (Arial = 4) in the same template?

Surrogate

Not allways !
On my side function Fonttoid("Arial") have value  21 !
As I understand this function need for create system-independed solutions. It automatically get local fontID !

Eva

But if you used the same template as I, would you then have the same fontID? When I use this specific template, the Fonttoid("Arial") value is 4, but if I open a new blank Visio drawing, then Fonttoid("Arial") has value 21.

Surrogate

I think so !
Quote from: MSDN


Note
In most cases, the font identifier is system-specific. Although the font remains established once used in a file, the FONT function provides consistent access to a particular font across systems and versions of Visio. It is recommended that you use the FONT function to assign fonts instead of referring to font identifiers directly.
proof

Paul Herber

I must admit I've never understood the whys and wherefores of using a font ID rather than the font name, no other software I know of does such a thing. Some time ago I created some shapes for a company and they specified a certain font (a corporate thing), the font came out 1 off from what they wanted, to them it came out as Algerian or something!
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Eva

Thank you very much for all this information!

Eva

I found the cause of the problem: when I save the drawing.vsd to drawing.vsdx, the fontID changes when the drawing is opened next time. The font name remains the same ("Arial"), but its ID in the Font cell changes (from 4 to 21). Otherwise it seems to remain the same in the same drawing / template, but it changes when the format changes. Thank you for helping me find this out!