473,386 Members | 1,969 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,386 software developers and data experts.

Special characters with DrawString?!

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 tutorial. Below is my code.

Thanks for any kind of help!

Regards,
Jonah Olsson
Dim b As Bitmap = New Bitmap(1, 1)
Dim g As Graphics = Graphics.FromImage(b)
Dim solidBrush As SolidBrush = New SolidBrush(TextColor)

Dim privateFontCollection As PrivateFontCollection = New
PrivateFontCollection
privateFontCollection.AddFontFile(Server.MapPath(" Static/Fonts/TELEBC__.TTF"
))

Dim thisFont As FontFamily = privateFontCollection.Families(0)
Dim regFont As Font = New Font(thisFont, FontSize, FontStyle.Bold,
GraphicsUnit.Pixel)

Dim Width As Integer
Width = Convert.ToInt32(g.MeasureString(Text, regFont).Width)
Dim Height As Integer
Height = Convert.ToInt32(g.MeasureString(Text, regFont).Height)

b = New Bitmap(Width, Height, PixelFormat.Format24bppRgb)

g = Graphics.FromImage(b)

g.TextRenderingHint = TextRenderingHint.AntiAlias
g.SmoothingMode = SmoothingMode.AntiAlias
g.Clear(BackColor)
g.DrawString(Text, regFont, solidBrush, 0, 0,
StringFormat.GenericTypographic)

Response.ContentType = "image/gif"
b.Save(Response.OutputStream, ImageFormat.Gif)
b.Dispose()
Nov 17 '05 #1
3 2032
Jonah,

It probably depends on whether the font you use is a Unicode one. If it is
not unicode, character translation should be done to match Swedich
characters stored as Unicode ones in a String with the code page the Font
uses. To set up this code page, use the GdiCharSet property of the Font
class.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Jonah Olsson" <jo***@IHateSpam.com> wrote in message
news:eW**************@TK2MSFTNGP10.phx.gbl...
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 tutorial. Below is my code.

Thanks for any kind of help!

Regards,
Jonah Olsson
Dim b As Bitmap = New Bitmap(1, 1)
Dim g As Graphics = Graphics.FromImage(b)
Dim solidBrush As SolidBrush = New SolidBrush(TextColor)

Dim privateFontCollection As PrivateFontCollection = New
PrivateFontCollection
privateFontCollection.AddFontFile(Server.MapPath(" Static/Fonts/TELEBC__.TTF" ))

Dim thisFont As FontFamily = privateFontCollection.Families(0)
Dim regFont As Font = New Font(thisFont, FontSize, FontStyle.Bold,
GraphicsUnit.Pixel)

Dim Width As Integer
Width = Convert.ToInt32(g.MeasureString(Text, regFont).Width)
Dim Height As Integer
Height = Convert.ToInt32(g.MeasureString(Text, regFont).Height)

b = New Bitmap(Width, Height, PixelFormat.Format24bppRgb)

g = Graphics.FromImage(b)

g.TextRenderingHint = TextRenderingHint.AntiAlias
g.SmoothingMode = SmoothingMode.AntiAlias
g.Clear(BackColor)
g.DrawString(Text, regFont, solidBrush, 0, 0,
StringFormat.GenericTypographic)

Response.ContentType = "image/gif"
b.Save(Response.OutputStream, ImageFormat.Gif)
b.Dispose()


Nov 17 '05 #2
Hi Dmitriy,

I solved the problem by using UrlEncode and UrlDecode, but that feels like a
bad work around. I have to call the web page (in <img src="...">) with
Web.HttpUtility.UrlEncode(...) and then decode the string in my code.

I'll try to set the GdiCharSet to see if there's a way I can skip the encode
and decode part.

Thanks.
Jonah
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> skrev i
meddelandet news:3f********@nexus.validio.com.ua...
Jonah,

It probably depends on whether the font you use is a Unicode one. If it is
not unicode, character translation should be done to match Swedich
characters stored as Unicode ones in a String with the code page the Font
uses. To set up this code page, use the GdiCharSet property of the Font
class.

Nov 17 '05 #3
Jonah,

Oops, I assumed you used Windows Forms. With the Web, you should set a
correct encoding for the web page in the appropriate meta tag (as well as in
the "Content-Type" header). I am not completely sure, but the HttpResponse
class should have the Encoding property. Set properly, it should
automatically take care over encoding the Unicode characters you send to the
response stream to the right code page.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Jonah Olsson" <jo***@IHateSpam.com> wrote in message
news:uG*************@TK2MSFTNGP12.phx.gbl...
Hi Dmitriy,

I solved the problem by using UrlEncode and UrlDecode, but that feels like a bad work around. I have to call the web page (in <img src="...">) with
Web.HttpUtility.UrlEncode(...) and then decode the string in my code.

I'll try to set the GdiCharSet to see if there's a way I can skip the encode and decode part.

Thanks.
Jonah
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> skrev i meddelandet news:3f********@nexus.validio.com.ua...
Jonah,

It probably depends on whether the font you use is a Unicode one. If it is not unicode, character translation should be done to match Swedich
characters stored as Unicode ones in a String with the code page the Font uses. To set up this code page, use the GdiCharSet property of the Font
class.



Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Roy W. Andersen | last post by:
I've been searching google about this for days but can't find anything, so I'm hoping someone here can help me out. I'm trying to create zip-files without needing the zip-file extension in PHP,...
3
by: Barry Olly | last post by:
Hi, I'm working on a mini content management system and need help with dealing with special characters. The input are taken from html form which are then stored into a varchar column in...
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: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
1
by: sonald | last post by:
Dear All, I am working on a module that validates the provided CSV data in a text format, which must be in a predefined format. We check for the : 1. Number of fields provided in the text file,...
3
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
I'm drawing text using the DrawString method. I need a way to go back and erase one or more characters. As a first thought it seemed that one way to do it would be to go back to the character(s)...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
6
by: vaskarbasak | last post by:
Hi all, I am trying to display a Chinese string (UTF-8) with Graphics2D.drawString() but nothing is displayed. here i paste my code package com; import java.awt.*; import...
6
vekipeki
by: vekipeki | last post by:
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#...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.