473,320 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

.NET Graphics.DrawString with Unicode characters

vekipeki
229 Expert 100+
I am having a problem with basic drawing of unicode characters in Windows 2000 and XP.

I have written a simplest possible C# WinForms program to test it (just create a new Windows Forms C# application and add a Paint event handler):

Expand|Select|Wrap|Line Numbers
  1. public partial class Form1 : Form
  2. {
  3.     public Form1()
  4.     {
  5.         InitializeComponent();
  6.         this.Paint += new PaintEventHandler(Form1_Paint);
  7.     }
  8.  
  9.     void Form1_Paint(object sender, PaintEventArgs e)
  10.     {
  11.         Font f = new Font("Tahoma", 12); // this is used just to get a larger font
  12.  
  13.         // try drawing with DrawString
  14.         e.Graphics.DrawString("Test \u2153", f, SystemBrushes.ControlText, new PointF(10, 50));
  15.  
  16.         // try drawing with DrawText
  17.         TextRenderer.DrawText(e.Graphics, "Test \u2153", f, new Rectangle(10, 10, 50, 50), SystemColors.ControlText);
  18.     }
  19. }
  20.  
In Windows Vista, the unicode character (U2153, representing "1/3" in a single character) is drawn twice, but in Windows XP or 2000, it is not drawn in any case.

So, the question is: how to draw a unicode string in XP?

[EDIT:] I just found out something, but decided to add this post anyway: the main problem is - Windows XP Tahoma font simply does not have these characters! When you try to insert this unicode symbol in MS Word using Tahoma font, it is omitted from the list (http://zero2180.net/2008/01/tahoma/).

I usually use SystemFonts.MessageBoxFont to get the default system font (returns "Tahoma" for XP and 2000, "Segoe" for Vista).

So what font should I then use for unicode?
Sep 30 '08 #1
6 10601
Plater
7,872 Expert 4TB
Find one that supports the characters you want and use that font?
Sep 30 '08 #2
vekipeki
229 Expert 100+
Well actually I haven't succeeded writing a superscript "+" sign using any of the common Windows fonts in w2k. For example, Arial Unicode MS font (which is said to be one of Microsoft's most-complete fonts in sense of unicode support), is not included by default in my win2k sp4 installation (does it come with Office?).

I don't like the idea of an application installing its fonts to the system, and I don't like the idea of using the Arial font instead of Tahoma just to get a couple of glyphs - I try to follow the Windows GUI design guidelines and they suggest avoiding non-system-default fonts in controls. I usually use SystemFonts.MessageBoxFont, and I presume (I hope correctly) that it will return a font which supports locale characters on a given machine - we might decide to localize our application to Chinese one day!

So at the end, what I wanted to avoid was using DrawString to manually create subscript and superscript signs because I thought the win2k and xp "unicode" fonts supported them.


I have two clean Virtual PC installations of win2k and xp, and have also modified my first program to try some other fonts:

Expand|Select|Wrap|Line Numbers
  1. using System.Windows.Forms;
  2. using System.Drawing;
  3.  
  4. public partial class Form1 : Form
  5. {
  6.     public Form1()
  7.     {
  8.         InitializeComponent();
  9.         this.Paint += new PaintEventHandler(Form1_Paint);
  10.     }
  11.  
  12.     void Form1_Paint(object sender, PaintEventArgs e)
  13.     {
  14.         string[] fontNames = new string[]
  15.              {  "Arial",
  16.                 "Tahoma",
  17.                 "Microsoft Sans Serif",
  18.                 "Arial Unicode MS",
  19.                 "Lucida Sans Unicode",
  20.                 "MS Sans Serif", 
  21.                 SystemFonts.DefaultFont.FontFamily.Name,
  22.                 SystemFonts.MessageBoxFont.FontFamily.Name };
  23.  
  24.         int yOffset = 10;
  25.  
  26.         foreach (string f in fontNames)
  27.             using (Font fnt = new Font(f, 12))
  28.             {
  29.                 e.Graphics.DrawString(fnt.FontFamily.ToString() + " \u2153", fnt, SystemBrushes.ControlText, new PointF(10, yOffset)); yOffset += 20;
  30.                 TextRenderer.DrawText(e.Graphics, fnt.FontFamily.ToString() + " \u2153", fnt, new Point(10, yOffset), SystemColors.ControlText); yOffset += 20;
  31.             }
  32.     }
  33. }
  34.  
It has a list of constant font family names, and two system defined fonts at the end. Windows XP shows the "1/3" glyph only with plain Arial font, but Win 2000 does not show it using any of the fonts.

Can anyone tell me if there is a font which works for you in w2k, and should be included by default?
Oct 1 '08 #3
Plater
7,872 Expert 4TB
Have you checked using charmap?
I avoid win2k like the plague so I don't have access to it anymore.
Oct 1 '08 #4
vekipeki
229 Expert 100+
Thanks for the tip, I haven't used Char. map for a long time. I started it in both windows xp and 2000, and found which fonts support which glyphs.

They are pretty mixed up, so I will probably try to isolate those special glyphs and handle them separately, leaving MessageBoxFont as the default font for normal text. Should have done it in the first place! :)

Thanks!
Oct 1 '08 #5
mdjuit
1
How to use charmap for special character for writing a string in drawstring?

I have a long string, trying to print it using drawstring function, but the special character are getting doubled in the output print. Please help me how to use charmap to get rid of this problem. Your suggestion is very important for me
Feb 3 '10 #6
tlhintoq
3,525 Expert 2GB
ell actually I haven't succeeded writing a superscript "+" sign
It might just be easiest to check the unicode standard at unicode.org
http://www.unicode.org/charts/

You'll find that superscript plus is 207A
http://www.unicode.org/charts/PDF/U2070.pdf

1/3 is 2153
http://www.unicode.org/charts/PDF/U2150.pdf
Feb 4 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jonah Olsson | last post by:
Hi guys! I'm trying to use Swedish characters with DrawString but no luck. Do I need to set the Charset somewhere?? I've been searching Google Groups for hours now, but I can't find any help or...
5
by: Charles A. Lackman | last post by:
Hello, I have created a complete PrintDocument and need to create an image from it. How is this done? e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality...
3
by: Gürkan Demirci | last post by:
Hi, i am trying to write Jananese characters with DrawString(). It is not working. The characters a printed as boxes only. How can i change the culture of my windows forms application ? It...
7
by: Michael Galvin | last post by:
I am trying to use Python to send to the printer a calender filled with a mix of text and simple graphics. I want to draw on the printed page something like a table with 6 rows and 7 columns to...
7
by: Peter Row | last post by:
Hi, I've started work on my own control some parts of which use standard controls, others I need to draw on my controls surface to get the display output I require, however.... I seem to be...
4
by: grawsha2000 | last post by:
Hi, Is there a way to force Graphics.drawstring() method to display Hindi numbers when printing? I changed the locale settings of the Regional Options to an Arabic lang. but no luck. ...
2
by: Tony Johansson | last post by:
Hello! If I use the DrawString below with object of StringFormat as the last object it works good. If I instead remove object StringFormat below as the last object of DrawString I get some rows...
6
by: Dilip | last post by:
Howdy Folks I have a display where the Graphics.DrawString function is called to display something. Since the text seems to be larger than its bounding rectangle, the call basically splits the...
10
by: anuking | last post by:
Hi, I made a tool that compares the texts from 2 richtextboxes and then marks the characters that are different in red. An option needs me to overlap these 2 text data to show the exact...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.