473,698 Members | 2,737 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 2223
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
8997
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 have the same problem. I'm currently using PclZip (http://phpconcept.net/pclzip/) but even the...
3
17198
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
2048
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
8620
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 file path. Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As
8
3706
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box and save it to a file. This step is not to hard however the contents of the textarea is mostly latex source so it contains just about every special character you can imagine. My question is this, how do I save an exact copy of the textarea...
1
4564
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
2084
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 code does that: protected override void OnPaint(PaintEventArgs pea) { Graphics grfx =...
3
10192
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 to read some regular expression tutorial. See the end of the article for links to online resources....
6
6186
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
10699
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
8683
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8902
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
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
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.