GraphicsPath AddString not support enough to the font when use right to left language if operating system...












7















I need to generate an image from a string in my WPF application, and show it. Here is my code:



// Create Image and generate string on it
ystem.Windows.Controls.Image img = new System.Windows.Controls.Image();


// This is the font that I need to render
Font DefaultFont = new Font("Oybab Tuz", 40f, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel);

// Generate image from string
GraphicsPath graphicsPath = new GraphicsPath();

// As you see, the string include Right to left character, also include some other character in the middle
graphicsPath.AddString("سىناق123456789سىناق", DefaultFont.FontFamily, (int)DefaultFont.Style, DefaultFont.Size * 96f / 72f, new PointF(0f, 0f), StringFormat.GenericDefault);

// Turn the string to the image
RectangleF bounds = graphicsPath.GetBounds();

Bitmap bitmap = new Bitmap((int)(bounds.Width + bounds.X), (int)(bounds.Height + bounds.Y));
Graphics graphic = Graphics.FromImage(bitmap);

graphic.FillPath(new SolidBrush(System.Drawing.Color.FromArgb(0x33, 0x00, 0xFF)), graphicsPath);
graphicsPath.Dispose();
graphic.Dispose();


// turn the Image to ImageSource
MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, ImageFormat.Png);

img.Source = (ImageSource)(new ImageSourceConverter()).ConvertFrom(memoryStream);

// Add the image to the window content
this.Content = img;


Now this will display perfectly fine in windows 10, such like this:



In the windows 10 operating system



But, if the operating system lower than Windows 10, such like: Windows XP, Windows 7, Windows 8.X, it will display like this:



enter image description here



Also not only the number, if I put some other character such like :"&&"




"سىناق&&سىناق"




The lower operating system still shows it like:




"سىناق سىناق"




it seems like the operating system auto remove the characters in the middle.



I knew the font which I'm using is not include the number or the character which I put in it, But Windows 10 could display it right.



Here is the font: Download font file



Because the character will not only display in a specific place, so I can't split the string, and render it one by one.



So I really want to know why, also I hope some guys could give me advice to fix this problem when operating system lower than Windows 10. Thank you.










share|improve this question

























  • The net library for a lot of methods are just wrappers that call windows dll. So if there is an operating difference then there are issues with the windows dll, the culture settings on the PC are different, or the installed fonts are different. Do you have all the windows updates on the PCs? What fonts are you using? Windows will automatically choose the closest font if the one selected is not available. Probably this error is due to different fonts being used. Find out the Font name that is being used in good and bad results.

    – jdweng
    Dec 25 '18 at 11:57











  • @jdweng, Thanks for reply, the font file address I have put it in my question, I also sure I install the all update in every operating system, I also confirm the culture settings are same and operating system is clean, not other fonts in it.

    – qakmak
    Dec 25 '18 at 12:06











  • Are all your characters support in the font. I suspect you have "Non Supported Unicode Characters". See : wavemetrics.com/forum/general/…

    – jdweng
    Dec 25 '18 at 13:12











  • @jdweng, As I said in my question before, the number and some character Not in the font, but I just want it work in lower version operating system as like Windows 10.

    – qakmak
    Dec 25 '18 at 13:43











  • I'm not sure how to fix. I do not think you want to make TUZ the default font since it is missing characters. You want the default font to contain all characters. Then use TUZ as the selected font. Using the Character Map tool in Word/Excel you allow you to adding missing characters to the TUZ font. That would be manual and do not know how to do it in software. I would use Excel and open the Character Map for TUZ and see what characters are missing.

    – jdweng
    Dec 25 '18 at 15:16
















7















I need to generate an image from a string in my WPF application, and show it. Here is my code:



// Create Image and generate string on it
ystem.Windows.Controls.Image img = new System.Windows.Controls.Image();


// This is the font that I need to render
Font DefaultFont = new Font("Oybab Tuz", 40f, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel);

// Generate image from string
GraphicsPath graphicsPath = new GraphicsPath();

// As you see, the string include Right to left character, also include some other character in the middle
graphicsPath.AddString("سىناق123456789سىناق", DefaultFont.FontFamily, (int)DefaultFont.Style, DefaultFont.Size * 96f / 72f, new PointF(0f, 0f), StringFormat.GenericDefault);

// Turn the string to the image
RectangleF bounds = graphicsPath.GetBounds();

Bitmap bitmap = new Bitmap((int)(bounds.Width + bounds.X), (int)(bounds.Height + bounds.Y));
Graphics graphic = Graphics.FromImage(bitmap);

graphic.FillPath(new SolidBrush(System.Drawing.Color.FromArgb(0x33, 0x00, 0xFF)), graphicsPath);
graphicsPath.Dispose();
graphic.Dispose();


// turn the Image to ImageSource
MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, ImageFormat.Png);

img.Source = (ImageSource)(new ImageSourceConverter()).ConvertFrom(memoryStream);

// Add the image to the window content
this.Content = img;


Now this will display perfectly fine in windows 10, such like this:



In the windows 10 operating system



But, if the operating system lower than Windows 10, such like: Windows XP, Windows 7, Windows 8.X, it will display like this:



enter image description here



Also not only the number, if I put some other character such like :"&&"




"سىناق&&سىناق"




The lower operating system still shows it like:




"سىناق سىناق"




it seems like the operating system auto remove the characters in the middle.



I knew the font which I'm using is not include the number or the character which I put in it, But Windows 10 could display it right.



Here is the font: Download font file



Because the character will not only display in a specific place, so I can't split the string, and render it one by one.



So I really want to know why, also I hope some guys could give me advice to fix this problem when operating system lower than Windows 10. Thank you.










share|improve this question

























  • The net library for a lot of methods are just wrappers that call windows dll. So if there is an operating difference then there are issues with the windows dll, the culture settings on the PC are different, or the installed fonts are different. Do you have all the windows updates on the PCs? What fonts are you using? Windows will automatically choose the closest font if the one selected is not available. Probably this error is due to different fonts being used. Find out the Font name that is being used in good and bad results.

    – jdweng
    Dec 25 '18 at 11:57











  • @jdweng, Thanks for reply, the font file address I have put it in my question, I also sure I install the all update in every operating system, I also confirm the culture settings are same and operating system is clean, not other fonts in it.

    – qakmak
    Dec 25 '18 at 12:06











  • Are all your characters support in the font. I suspect you have "Non Supported Unicode Characters". See : wavemetrics.com/forum/general/…

    – jdweng
    Dec 25 '18 at 13:12











  • @jdweng, As I said in my question before, the number and some character Not in the font, but I just want it work in lower version operating system as like Windows 10.

    – qakmak
    Dec 25 '18 at 13:43











  • I'm not sure how to fix. I do not think you want to make TUZ the default font since it is missing characters. You want the default font to contain all characters. Then use TUZ as the selected font. Using the Character Map tool in Word/Excel you allow you to adding missing characters to the TUZ font. That would be manual and do not know how to do it in software. I would use Excel and open the Character Map for TUZ and see what characters are missing.

    – jdweng
    Dec 25 '18 at 15:16














7












7








7


1






I need to generate an image from a string in my WPF application, and show it. Here is my code:



// Create Image and generate string on it
ystem.Windows.Controls.Image img = new System.Windows.Controls.Image();


// This is the font that I need to render
Font DefaultFont = new Font("Oybab Tuz", 40f, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel);

// Generate image from string
GraphicsPath graphicsPath = new GraphicsPath();

// As you see, the string include Right to left character, also include some other character in the middle
graphicsPath.AddString("سىناق123456789سىناق", DefaultFont.FontFamily, (int)DefaultFont.Style, DefaultFont.Size * 96f / 72f, new PointF(0f, 0f), StringFormat.GenericDefault);

// Turn the string to the image
RectangleF bounds = graphicsPath.GetBounds();

Bitmap bitmap = new Bitmap((int)(bounds.Width + bounds.X), (int)(bounds.Height + bounds.Y));
Graphics graphic = Graphics.FromImage(bitmap);

graphic.FillPath(new SolidBrush(System.Drawing.Color.FromArgb(0x33, 0x00, 0xFF)), graphicsPath);
graphicsPath.Dispose();
graphic.Dispose();


// turn the Image to ImageSource
MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, ImageFormat.Png);

img.Source = (ImageSource)(new ImageSourceConverter()).ConvertFrom(memoryStream);

// Add the image to the window content
this.Content = img;


Now this will display perfectly fine in windows 10, such like this:



In the windows 10 operating system



But, if the operating system lower than Windows 10, such like: Windows XP, Windows 7, Windows 8.X, it will display like this:



enter image description here



Also not only the number, if I put some other character such like :"&&"




"سىناق&&سىناق"




The lower operating system still shows it like:




"سىناق سىناق"




it seems like the operating system auto remove the characters in the middle.



I knew the font which I'm using is not include the number or the character which I put in it, But Windows 10 could display it right.



Here is the font: Download font file



Because the character will not only display in a specific place, so I can't split the string, and render it one by one.



So I really want to know why, also I hope some guys could give me advice to fix this problem when operating system lower than Windows 10. Thank you.










share|improve this question
















I need to generate an image from a string in my WPF application, and show it. Here is my code:



// Create Image and generate string on it
ystem.Windows.Controls.Image img = new System.Windows.Controls.Image();


// This is the font that I need to render
Font DefaultFont = new Font("Oybab Tuz", 40f, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel);

// Generate image from string
GraphicsPath graphicsPath = new GraphicsPath();

// As you see, the string include Right to left character, also include some other character in the middle
graphicsPath.AddString("سىناق123456789سىناق", DefaultFont.FontFamily, (int)DefaultFont.Style, DefaultFont.Size * 96f / 72f, new PointF(0f, 0f), StringFormat.GenericDefault);

// Turn the string to the image
RectangleF bounds = graphicsPath.GetBounds();

Bitmap bitmap = new Bitmap((int)(bounds.Width + bounds.X), (int)(bounds.Height + bounds.Y));
Graphics graphic = Graphics.FromImage(bitmap);

graphic.FillPath(new SolidBrush(System.Drawing.Color.FromArgb(0x33, 0x00, 0xFF)), graphicsPath);
graphicsPath.Dispose();
graphic.Dispose();


// turn the Image to ImageSource
MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, ImageFormat.Png);

img.Source = (ImageSource)(new ImageSourceConverter()).ConvertFrom(memoryStream);

// Add the image to the window content
this.Content = img;


Now this will display perfectly fine in windows 10, such like this:



In the windows 10 operating system



But, if the operating system lower than Windows 10, such like: Windows XP, Windows 7, Windows 8.X, it will display like this:



enter image description here



Also not only the number, if I put some other character such like :"&&"




"سىناق&&سىناق"




The lower operating system still shows it like:




"سىناق سىناق"




it seems like the operating system auto remove the characters in the middle.



I knew the font which I'm using is not include the number or the character which I put in it, But Windows 10 could display it right.



Here is the font: Download font file



Because the character will not only display in a specific place, so I can't split the string, and render it one by one.



So I really want to know why, also I hope some guys could give me advice to fix this problem when operating system lower than Windows 10. Thank you.







c# .net windows gdi+ gdi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 20:48







qakmak

















asked Dec 25 '18 at 11:47









qakmakqakmak

35342044




35342044













  • The net library for a lot of methods are just wrappers that call windows dll. So if there is an operating difference then there are issues with the windows dll, the culture settings on the PC are different, or the installed fonts are different. Do you have all the windows updates on the PCs? What fonts are you using? Windows will automatically choose the closest font if the one selected is not available. Probably this error is due to different fonts being used. Find out the Font name that is being used in good and bad results.

    – jdweng
    Dec 25 '18 at 11:57











  • @jdweng, Thanks for reply, the font file address I have put it in my question, I also sure I install the all update in every operating system, I also confirm the culture settings are same and operating system is clean, not other fonts in it.

    – qakmak
    Dec 25 '18 at 12:06











  • Are all your characters support in the font. I suspect you have "Non Supported Unicode Characters". See : wavemetrics.com/forum/general/…

    – jdweng
    Dec 25 '18 at 13:12











  • @jdweng, As I said in my question before, the number and some character Not in the font, but I just want it work in lower version operating system as like Windows 10.

    – qakmak
    Dec 25 '18 at 13:43











  • I'm not sure how to fix. I do not think you want to make TUZ the default font since it is missing characters. You want the default font to contain all characters. Then use TUZ as the selected font. Using the Character Map tool in Word/Excel you allow you to adding missing characters to the TUZ font. That would be manual and do not know how to do it in software. I would use Excel and open the Character Map for TUZ and see what characters are missing.

    – jdweng
    Dec 25 '18 at 15:16



















  • The net library for a lot of methods are just wrappers that call windows dll. So if there is an operating difference then there are issues with the windows dll, the culture settings on the PC are different, or the installed fonts are different. Do you have all the windows updates on the PCs? What fonts are you using? Windows will automatically choose the closest font if the one selected is not available. Probably this error is due to different fonts being used. Find out the Font name that is being used in good and bad results.

    – jdweng
    Dec 25 '18 at 11:57











  • @jdweng, Thanks for reply, the font file address I have put it in my question, I also sure I install the all update in every operating system, I also confirm the culture settings are same and operating system is clean, not other fonts in it.

    – qakmak
    Dec 25 '18 at 12:06











  • Are all your characters support in the font. I suspect you have "Non Supported Unicode Characters". See : wavemetrics.com/forum/general/…

    – jdweng
    Dec 25 '18 at 13:12











  • @jdweng, As I said in my question before, the number and some character Not in the font, but I just want it work in lower version operating system as like Windows 10.

    – qakmak
    Dec 25 '18 at 13:43











  • I'm not sure how to fix. I do not think you want to make TUZ the default font since it is missing characters. You want the default font to contain all characters. Then use TUZ as the selected font. Using the Character Map tool in Word/Excel you allow you to adding missing characters to the TUZ font. That would be manual and do not know how to do it in software. I would use Excel and open the Character Map for TUZ and see what characters are missing.

    – jdweng
    Dec 25 '18 at 15:16

















The net library for a lot of methods are just wrappers that call windows dll. So if there is an operating difference then there are issues with the windows dll, the culture settings on the PC are different, or the installed fonts are different. Do you have all the windows updates on the PCs? What fonts are you using? Windows will automatically choose the closest font if the one selected is not available. Probably this error is due to different fonts being used. Find out the Font name that is being used in good and bad results.

– jdweng
Dec 25 '18 at 11:57





The net library for a lot of methods are just wrappers that call windows dll. So if there is an operating difference then there are issues with the windows dll, the culture settings on the PC are different, or the installed fonts are different. Do you have all the windows updates on the PCs? What fonts are you using? Windows will automatically choose the closest font if the one selected is not available. Probably this error is due to different fonts being used. Find out the Font name that is being used in good and bad results.

– jdweng
Dec 25 '18 at 11:57













@jdweng, Thanks for reply, the font file address I have put it in my question, I also sure I install the all update in every operating system, I also confirm the culture settings are same and operating system is clean, not other fonts in it.

– qakmak
Dec 25 '18 at 12:06





@jdweng, Thanks for reply, the font file address I have put it in my question, I also sure I install the all update in every operating system, I also confirm the culture settings are same and operating system is clean, not other fonts in it.

– qakmak
Dec 25 '18 at 12:06













Are all your characters support in the font. I suspect you have "Non Supported Unicode Characters". See : wavemetrics.com/forum/general/…

– jdweng
Dec 25 '18 at 13:12





Are all your characters support in the font. I suspect you have "Non Supported Unicode Characters". See : wavemetrics.com/forum/general/…

– jdweng
Dec 25 '18 at 13:12













@jdweng, As I said in my question before, the number and some character Not in the font, but I just want it work in lower version operating system as like Windows 10.

– qakmak
Dec 25 '18 at 13:43





@jdweng, As I said in my question before, the number and some character Not in the font, but I just want it work in lower version operating system as like Windows 10.

– qakmak
Dec 25 '18 at 13:43













I'm not sure how to fix. I do not think you want to make TUZ the default font since it is missing characters. You want the default font to contain all characters. Then use TUZ as the selected font. Using the Character Map tool in Word/Excel you allow you to adding missing characters to the TUZ font. That would be manual and do not know how to do it in software. I would use Excel and open the Character Map for TUZ and see what characters are missing.

– jdweng
Dec 25 '18 at 15:16





I'm not sure how to fix. I do not think you want to make TUZ the default font since it is missing characters. You want the default font to contain all characters. Then use TUZ as the selected font. Using the Character Map tool in Word/Excel you allow you to adding missing characters to the TUZ font. That would be manual and do not know how to do it in software. I would use Excel and open the Character Map for TUZ and see what characters are missing.

– jdweng
Dec 25 '18 at 15:16












1 Answer
1






active

oldest

votes


















-1














I found the following question from the past :



Generic GDI+ exception in GraphicsPath.AddString() with certain fonts and characters



It my be that in older versions of windows you will face some issues,
There is a link for a specific KB that suppose to fix it - worth trying :)



By the way have you tried it with other fonts types or change font types just to check if something will change.



Hope it helped



Asaf






share|improve this answer
























  • But how about in windows 8.1 and windows server 2012?

    – qakmak
    Jan 2 at 12:09











  • Also how about XP?

    – qakmak
    Jan 2 at 17:30











  • Hi, It is a Microsoft know issue. If they solved it just for Windows 7 , Vista and a few Servers there is nothing that i can do about it ;).

    – Asaf
    Jan 3 at 5:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53922087%2fgraphicspath-addstring-not-support-enough-to-the-font-when-use-right-to-left-lan%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1














I found the following question from the past :



Generic GDI+ exception in GraphicsPath.AddString() with certain fonts and characters



It my be that in older versions of windows you will face some issues,
There is a link for a specific KB that suppose to fix it - worth trying :)



By the way have you tried it with other fonts types or change font types just to check if something will change.



Hope it helped



Asaf






share|improve this answer
























  • But how about in windows 8.1 and windows server 2012?

    – qakmak
    Jan 2 at 12:09











  • Also how about XP?

    – qakmak
    Jan 2 at 17:30











  • Hi, It is a Microsoft know issue. If they solved it just for Windows 7 , Vista and a few Servers there is nothing that i can do about it ;).

    – Asaf
    Jan 3 at 5:23
















-1














I found the following question from the past :



Generic GDI+ exception in GraphicsPath.AddString() with certain fonts and characters



It my be that in older versions of windows you will face some issues,
There is a link for a specific KB that suppose to fix it - worth trying :)



By the way have you tried it with other fonts types or change font types just to check if something will change.



Hope it helped



Asaf






share|improve this answer
























  • But how about in windows 8.1 and windows server 2012?

    – qakmak
    Jan 2 at 12:09











  • Also how about XP?

    – qakmak
    Jan 2 at 17:30











  • Hi, It is a Microsoft know issue. If they solved it just for Windows 7 , Vista and a few Servers there is nothing that i can do about it ;).

    – Asaf
    Jan 3 at 5:23














-1












-1








-1







I found the following question from the past :



Generic GDI+ exception in GraphicsPath.AddString() with certain fonts and characters



It my be that in older versions of windows you will face some issues,
There is a link for a specific KB that suppose to fix it - worth trying :)



By the way have you tried it with other fonts types or change font types just to check if something will change.



Hope it helped



Asaf






share|improve this answer













I found the following question from the past :



Generic GDI+ exception in GraphicsPath.AddString() with certain fonts and characters



It my be that in older versions of windows you will face some issues,
There is a link for a specific KB that suppose to fix it - worth trying :)



By the way have you tried it with other fonts types or change font types just to check if something will change.



Hope it helped



Asaf







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 1 at 5:53









AsafAsaf

452




452













  • But how about in windows 8.1 and windows server 2012?

    – qakmak
    Jan 2 at 12:09











  • Also how about XP?

    – qakmak
    Jan 2 at 17:30











  • Hi, It is a Microsoft know issue. If they solved it just for Windows 7 , Vista and a few Servers there is nothing that i can do about it ;).

    – Asaf
    Jan 3 at 5:23



















  • But how about in windows 8.1 and windows server 2012?

    – qakmak
    Jan 2 at 12:09











  • Also how about XP?

    – qakmak
    Jan 2 at 17:30











  • Hi, It is a Microsoft know issue. If they solved it just for Windows 7 , Vista and a few Servers there is nothing that i can do about it ;).

    – Asaf
    Jan 3 at 5:23

















But how about in windows 8.1 and windows server 2012?

– qakmak
Jan 2 at 12:09





But how about in windows 8.1 and windows server 2012?

– qakmak
Jan 2 at 12:09













Also how about XP?

– qakmak
Jan 2 at 17:30





Also how about XP?

– qakmak
Jan 2 at 17:30













Hi, It is a Microsoft know issue. If they solved it just for Windows 7 , Vista and a few Servers there is nothing that i can do about it ;).

– Asaf
Jan 3 at 5:23





Hi, It is a Microsoft know issue. If they solved it just for Windows 7 , Vista and a few Servers there is nothing that i can do about it ;).

– Asaf
Jan 3 at 5:23




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53922087%2fgraphicspath-addstring-not-support-enough-to-the-font-when-use-right-to-left-lan%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith