473,569 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.FromIm age(b)
Dim solidBrush As SolidBrush = New SolidBrush(Text Color)

Dim privateFontColl ection As PrivateFontColl ection = New
PrivateFontColl ection
privateFontColl ection.AddFontF ile(Server.MapP ath("Static/Fonts/TELEBC__.TTF"
))

Dim thisFont As FontFamily = privateFontColl ection.Families (0)
Dim regFont As Font = New Font(thisFont, FontSize, FontStyle.Bold,
GraphicsUnit.Pi xel)

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

b = New Bitmap(Width, Height, PixelFormat.For mat24bppRgb)

g = Graphics.FromIm age(b)

g.TextRendering Hint = TextRenderingHi nt.AntiAlias
g.SmoothingMode = SmoothingMode.A ntiAlias
g.Clear(BackCol or)
g.DrawString(Te xt, regFont, solidBrush, 0, 0,
StringFormat.Ge nericTypographi c)

Response.Conten tType = "image/gif"
b.Save(Response .OutputStream, ImageFormat.Gif )
b.Dispose()
Nov 17 '05 #1
3 2039
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***@IHateSpa m.com> wrote in message
news:eW******** ******@TK2MSFTN GP10.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.FromIm age(b)
Dim solidBrush As SolidBrush = New SolidBrush(Text Color)

Dim privateFontColl ection As PrivateFontColl ection = New
PrivateFontColl ection
privateFontColl ection.AddFontF ile(Server.MapP ath("Static/Fonts/TELEBC__.TTF" ))

Dim thisFont As FontFamily = privateFontColl ection.Families (0)
Dim regFont As Font = New Font(thisFont, FontSize, FontStyle.Bold,
GraphicsUnit.Pi xel)

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

b = New Bitmap(Width, Height, PixelFormat.For mat24bppRgb)

g = Graphics.FromIm age(b)

g.TextRendering Hint = TextRenderingHi nt.AntiAlias
g.SmoothingMode = SmoothingMode.A ntiAlias
g.Clear(BackCol or)
g.DrawString(Te xt, regFont, solidBrush, 0, 0,
StringFormat.Ge nericTypographi c)

Response.Conten tType = "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.c om> 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***@IHateSpa m.com> wrote in message
news:uG******** *****@TK2MSFTNG P12.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.c om> 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
8974
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, mainly because I need the ability to both create and extract zip-files. I've tried a couple of classes found here and there, and they all seem to...
3
17190
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 oracle database. When i retrieve the data, some of the special characters have been changed to ??? and also
3
2216
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 tutorial. Below is my code. Thanks for any kind of help! Regards, Jonah Olsson
5
8605
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". Same file path containing special characters works fine in one machine, but doesn't work in other. I am using following API function to get short...
1
4555
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, 2. Text checks for max. length of the field & whether the field is mandatory or optional Example:
3
2082
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) I want to erase and merely re-write the same character(s) using a brush whose foreground color is the same as the background color. The following...
3
10186
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. This is not a regular expression tutorial. Assumes you are already familiar with basic regular expression concepts and terminology. If not, you may want...
6
6145
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 java.awt.image.*; import java.io.*;
6
10658
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# application and add a Paint event handler): public partial class Form1 : Form { public Form1() { InitializeComponent();
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.