0

Currently I have a piece of code that generates an image, however when I upload my solution to a cloud linux environment the font size in the image changes. This is causing many problems, is there a way in which I can specify a "Windows font" something that can indicate Linux to not use its own fonts but use the ones provided?

This is the code I am using to create the font:

var bannersFont = new Font("Arial Narrow", 10, FontStyle.Bold);

As you can see down below the image to the left is generated locally in my machine and the image to the right is generated after the code is uploaded to the cloud Linux environment. We can see that the font is coming out much smaller, can I specify a type of font that would match in both a windows and a linux environments?

Arial Narrow font size comparison

These are the two files of the images enter image description here

Lostaunaum
  • 697
  • 1
  • 10
  • 31
  • Maybe the `PrivateFontCollection` can help you. https://msdn.microsoft.com/en-us/library/system.drawing.text.privatefontcollection(v=vs.110).aspx – Ben Jul 20 '17 at 17:10
  • @Ben how can I implement PrivateFontCollection in my context? I tried Using, new Font("Arial Narrow", 10, FontStyle.Bold, GraphicsUnit.Point); but that did not work.... – Lostaunaum Jul 20 '17 at 17:31
  • Here is an example on how to use it https://stackoverflow.com/questions/15949057/addfontfile-from-resources – Ben Jul 20 '17 at 17:33
  • 1
    The fonts are the same size: 10 pt = 10/72 inches = 0.14 inches = 0.35 cm. However, the left display is a high res 144 dpi display where 0.35 cm on screen is 20 px, while the right display is lower res where 0.35 cm is 10px. If you're aiming for the same pixel height instead of the same display height, you have to adjust for the DPI on each target. – that other guy Jul 20 '17 at 17:41
  • @thatotherguy I dont understand, I am adjusting the DPI and the resolution of the image when I create it locally it produces the image on the left, however when I create it in Linux it produces the image on the right. Why would the DPI change? – Lostaunaum Jul 20 '17 at 17:44
  • @thatotherguy I added an image comparing both files so you can see they have the same exact dimensions and the bit depths, I feel as though this issue has to be a font issue. But I may be wrong. – Lostaunaum Jul 20 '17 at 17:51
  • @Ben Even if add the fonts to the memory woudlnt the issue still persist? If I add Arial Narrow font it will still be displayed as smaller? – Lostaunaum Jul 20 '17 at 17:55
  • @Lostaunaum: It's true that won't solve your problem, but it does answer the question you asked. Namely, "is there a way in which I can specify a "Windows font" something that can indicate Linux to not use its own fonts but use the ones provided?" – Ben Voigt Jul 20 '17 at 17:57
  • try it. Right now the font on the right is not the same font like on the left. I think you should test if you have the same result, when you are using the same font on both windows and Linux. – Ben Jul 20 '17 at 17:59
  • @Ben Ill give it a try, maybe if I specify the font it will match... I am not 100% that will solve this issue. It seems as though there may be other issues affecting this – Lostaunaum Jul 20 '17 at 17:59
  • @Lostaunaum I don't see you adjusting the DPI, only the pixel size. A Surface Pro defaults to 144 dpi while X.org on Linux defaults to 96 dpi for example, so one will think that a 10 point font will be more pixels than the other. I don't know this C# API, but Google suggests you can see this difference with `Graphics.DpiX` and `.DpiY` and that `Font` has a constructor where you can specify GraphicsUnit as Pixels instead of Points. – that other guy Jul 20 '17 at 18:03
  • 1
    @thatotherguy I am not adjusting the DPI in this part of the code, but I am drawing all of this on an exsting Bitmap //create a new image of the right size //203 DPI is Standard for Newgistics ZPL printers var img = new Bitmap(812, 1015); img.SetResolution(203, 203); var drawing = Graphics.FromImage(img); – Lostaunaum Jul 20 '17 at 18:11
  • @Ben I tried adding a file font and loading it but it still comes out small. I think the graphics maybe the one to blame for this. I will look into it further. Any suggestions are appreciated. – Lostaunaum Jul 21 '17 at 14:54

0 Answers0