Notifications
Clear all

[Closed] How to embed a font in mxs?

Hi,
I need simpliest solution (ie example) for embeding custom font (True Type or Open Type)
without install it and use after as default font for dotnet label control inside mxs rollout.
I saw an example in which Pete (lonerobot) use functions for converting images to Base64 string
but is it possible to perform the same with a font?
Second request:
How to writte these code as mxs (not compiling)

public static LoadedFont LoadFont(FileInfo file, int fontSize, FontStyle fontStyle)
   {
 	  var fontCollection = new PrivateFontCollection();
 	  fontCollection.AddFontFile(file.FullName);
 	  if (fontCollection.Families.Length < 0)
 	  {
 		  throw new InvalidOperationException("No font familiy found when loading font");
 	  }
 
 	  var loadedFont = new LoadedFont();
 	  loadedFont.FontFamily = fontCollection.Families[0];
 	  loadedFont.Font = new Font(loadedFont.FontFamily, fontSize, fontStyle, GraphicsUnit.Pixel);
 	  return loadedFont;
   }
 public struct LoadedFont
 {
  	public Font Font { get; set; }
  	public FontFamily FontFamily { get; set; }
 }

Thanks in advance
Branko

5 Replies

Anyone? Ok then.
The reason why i need this is that some system fonts have very nice simbol collections
which can be used as icons for buttons or labels.
But I would not like to install these fonts on another PC.

I don’t know about including fonts, but this is something that I have used to imbed bitmaps in MS, which I have used for icons etc…

It is not pretty, or nice, but it sure gets the job done.



bit1 = openbitmap "C:\myimage.bmp"

fn bitToStr bit1 =
(
	bitArr = #()
	for g in 0 to (bit1.height - 1) do
	(
		p = getPixels bit1 [0, g] bit1.width
		append bitArr p
	)
	
	(bitArr as string)
)

fn strToBit str =
(
	bitArr = execute str
	bit1 = bitmap bitArr[1].count bitArr.Count
	
	for q in 0 to bitArr.count - 1 do
	(
		setpixels bit1 [0, q] bitArr[q + 1]
	)
	
	bit1
)

str = bitToStr bit1

print str

bit2 = strToBit str

display bit2


The first chunk will turn your bitmap into a string, and the second bit will turn it back

Nice approach. Thanks Aaron for reply.
You are talking abouth bitmap but i was thinkig about
embeding font as vector icon not raster.
Probably you have seen fonts such as for example
system fonts “Webdings” and “Wingdings”.

Do you have solution for this?


(		
	fontCollection = dotnetobject "System.Drawing.Text.PrivateFontCollection"
	fontCollection.AddFontFile <the_TTF_font_filename>
	fontFamily = fontCollection.Families[1]
	font = dotnetobject "System.Drawing.Font" fontFamily 12 (dotnetclass "System.Drawing.FontStyle").Regular (dotnetclass "System.Drawing.GraphicsUnit").Pixel
)

Very nice.
Thanks Denis.
This is exactly what I was looking for.