Visio Guy

Visio Discussions => General Visio => Topic started by: Eva on February 14, 2018, 11:19:32 AM

Title: Setting a specific font programmatically
Post by: Eva on February 14, 2018, 11:19:32 AM
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
Title: Re: Setting a specific font programmatically
Post by: Surrogate on February 14, 2018, 12:28:12 PM
Hi, Eva !

You can also use FONTTOID function !
Font properties in ShapeSheet functions list (https://shapesheet-kb.github.io/en/pages/categories/Fonts.htm)
Title: Re: Setting a specific font programmatically
Post by: Eva on February 14, 2018, 12:45:38 PM
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
Title: Re: Setting a specific font programmatically
Post by: Surrogate on February 14, 2018, 12:47:35 PM
You mean VBA code?
Title: Re: Setting a specific font programmatically
Post by: Eva on February 14, 2018, 12:48:35 PM
I mean C# code.
Title: Re: Setting a specific font programmatically
Post by: Surrogate on February 14, 2018, 12:58:33 PM
I haven't Visual Studio there and great experience in C# :(

this code in VBA works

shp.CellsSRC(visSectionCharacter, 0, visCharacterFont).FormulaU = "Fonttoid(""Arial"")"
Title: Re: Setting a specific font programmatically
Post by: Surrogate on February 14, 2018, 01:13:59 PM
May be something like
Cell CellFont = shp.get_CellsSRC((short)VisSectionIndices.visSectionCharacter, 0, (short)VisCellIndices.visCharacterFont);
CellFont.FormulaU = "FONT(""Arial"")";

please try this code
Title: Re: Setting a specific font programmatically
Post by: Eva on February 14, 2018, 01:29:03 PM
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?
Title: Re: Setting a specific font programmatically
Post by: Surrogate on February 14, 2018, 01:34:26 PM
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 !
Title: Re: Setting a specific font programmatically
Post by: Eva on February 14, 2018, 01:44:53 PM
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.
Title: Re: Setting a specific font programmatically
Post by: Surrogate on February 14, 2018, 01:53:47 PM
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 (https://msdn.microsoft.com/en-us/library/office/jj227699.aspx)
Title: Re: Setting a specific font programmatically
Post by: Paul Herber on February 14, 2018, 02:51:10 PM
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!
Title: Re: Setting a specific font programmatically
Post by: Eva on February 14, 2018, 03:41:14 PM
Thank you very much for all this information!
Title: Re: Setting a specific font programmatically
Post by: Eva on February 15, 2018, 01:25:11 PM
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!