473,667 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reorder English text?

Hi,

Below is a calss with function I gathered from a news group that uses
GetCharacterPla cement API to reorder text.
I have mixed text Hebrew/English and the function reorders the Hebrew text.

I would like to reorder the English text instead the Hebrew text.

How can I do that please?

Regards,
Asaf
--------------------------------------------------------------------------------------------

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Drawing;
using System.Runtime. InteropServices ;
using System.Windows. Forms;

namespace GetCharacterPla cement
{
class FlipHebrew
{
[StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Auto)]
public struct GpcResults // Win32: GCP_RESULTS
{
public int StructSize;
[MarshalAs(Unman agedType.LPTStr )]
public string OutString;
public IntPtr Order;
public IntPtr Dx;
public IntPtr CaretPos;
public IntPtr Class;
public IntPtr Glyphs;
public int GlyphCount;
public int MaxFit;
}
[Flags]
public enum GcpFlags // Win32: GCP_xxx flags, WinGDI.h
{
DBCS = 0x00000001,
ReOrder = 0x00000002,
UseKerning = 0x00000008,
GlyphShape = 0x00000010,
Ligate = 0x00000020,
Diacritic = 0x00000100,
Kashida = 0x00000400,
Error = 0x00008000,
Justify = 0x00010000,
FliGlyphs = 0x00040000,
ClassIn = 0x00080000,
MaxExtent = 0x00100000,
JustifyIn = 0x00200000,
DisplayZWG = 0x00400000,
SymSwapOff = 0x00800000,
NumericOverride = 0x01000000,
NeutralOverride = 0x02000000,
NumericsLatin = 0x04000000,
NumericsLocal = 0x08000000,
FliMask = 0x0000103B
}

[DllImport("gdi3 2.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetCharacterPla cementW(IntPtr dev, string
text, int count, int max,
[In, Out] ref GpcResults results, GcpFlags flags);
[DllImport("gdi3 2.dll", ExactSpelling = true)]
public static extern GcpFlags GetFontLanguage Info(IntPtr dev);
public string funcGetCharacte rPlacement(stri ng sTextToFlip)
{
Panel pnl = new Panel();
Graphics g = pnl.CreateGraph ics();
IntPtr dev = g.GetHdc();

//string txt = "בדיקת עברית With English ועוד עברית";
string txt = sTextToFlip;
int len = txt.Length;

int[] order = new int[len];
int[] dx = new int[len];
int[] caret = new int[len];
byte[] clss = new byte[len];
short[] glys = new short[len];
GCHandle ordHnd = GCHandle.Alloc( order, GCHandleType.Pi nned);
GCHandle dxHnd = GCHandle.Alloc( dx, GCHandleType.Pi nned);
GCHandle carHnd = GCHandle.Alloc( caret, GCHandleType.Pi nned);
GCHandle clsHnd = GCHandle.Alloc( clss, GCHandleType.Pi nned);
GCHandle glyHnd = GCHandle.Alloc( glys, GCHandleType.Pi nned);
try
{
GpcResults rs = new GpcResults();
rs.StructSize = Marshal.SizeOf( typeof(GpcResul ts));
rs.OutString = new String('\0', len + 2);
rs.Order = ordHnd.AddrOfPi nnedObject();
rs.Dx = dxHnd.AddrOfPin nedObject();
rs.CaretPos = carHnd.AddrOfPi nnedObject();
rs.Class = clsHnd.AddrOfPi nnedObject();
rs.Glyphs = glyHnd.AddrOfPi nnedObject();
rs.GlyphCount = len;
rs.MaxFit = 0;
GcpFlags flg = GcpFlags.FliMas k & GetFontLanguage Info(dev);
int r = GetCharacterPla cementW(dev, txt, len, 0, ref rs, flg);
if (r == 0) // 0:Error; OK e.g. 0x100085
{
int err = Marshal.GetLast Win32Error();
// todo: error handling
}

return rs.OutString;
}
finally
{
ordHnd.Free();
dxHnd.Free();
carHnd.Free();
clsHnd.Free();
glyHnd.Free();
// e.Graphics.Rele aseHdc(dev);
}

}
}
}

Jan 19 '06 #1
2 3297
Asaf,

First, there is no reason to pin the variables down before the call to
GetCharacterPla cement. The interop layer will handle the pinning of the
variables for you.

Also, you realize that the documentation for GetCharacterPla cement
states:

Although this function was once adequate for working with character strings,
a need to work with an increasing number of languages and scripts has
rendered it obsolete. It has been superseded by the functionality of the
Uniscribe module. For more information, see Uniscribe.

You might want to check those APIs for a more suitable function to call.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Asaf" <AG**@newsgroup s.nospam> wrote in message
news:CC******** *************** ***********@mic rosoft.com...
Hi,

Below is a calss with function I gathered from a news group that uses
GetCharacterPla cement API to reorder text.
I have mixed text Hebrew/English and the function reorders the Hebrew
text.

I would like to reorder the English text instead the Hebrew text.

How can I do that please?

Regards,
Asaf
--------------------------------------------------------------------------------------------

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Drawing;
using System.Runtime. InteropServices ;
using System.Windows. Forms;

namespace GetCharacterPla cement
{
class FlipHebrew
{
[StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Auto)]
public struct GpcResults // Win32: GCP_RESULTS
{
public int StructSize;
[MarshalAs(Unman agedType.LPTStr )]
public string OutString;
public IntPtr Order;
public IntPtr Dx;
public IntPtr CaretPos;
public IntPtr Class;
public IntPtr Glyphs;
public int GlyphCount;
public int MaxFit;
}
[Flags]
public enum GcpFlags // Win32: GCP_xxx flags, WinGDI.h
{
DBCS = 0x00000001,
ReOrder = 0x00000002,
UseKerning = 0x00000008,
GlyphShape = 0x00000010,
Ligate = 0x00000020,
Diacritic = 0x00000100,
Kashida = 0x00000400,
Error = 0x00008000,
Justify = 0x00010000,
FliGlyphs = 0x00040000,
ClassIn = 0x00080000,
MaxExtent = 0x00100000,
JustifyIn = 0x00200000,
DisplayZWG = 0x00400000,
SymSwapOff = 0x00800000,
NumericOverride = 0x01000000,
NeutralOverride = 0x02000000,
NumericsLatin = 0x04000000,
NumericsLocal = 0x08000000,
FliMask = 0x0000103B
}

[DllImport("gdi3 2.dll", CharSet = CharSet.Auto, SetLastError =
true)]
public static extern int GetCharacterPla cementW(IntPtr dev, string
text, int count, int max,
[In, Out] ref GpcResults results, GcpFlags flags);
[DllImport("gdi3 2.dll", ExactSpelling = true)]
public static extern GcpFlags GetFontLanguage Info(IntPtr dev);
public string funcGetCharacte rPlacement(stri ng sTextToFlip)
{
Panel pnl = new Panel();
Graphics g = pnl.CreateGraph ics();
IntPtr dev = g.GetHdc();

//string txt = "????? ????? With English ???? ?????";
string txt = sTextToFlip;
int len = txt.Length;

int[] order = new int[len];
int[] dx = new int[len];
int[] caret = new int[len];
byte[] clss = new byte[len];
short[] glys = new short[len];
GCHandle ordHnd = GCHandle.Alloc( order, GCHandleType.Pi nned);
GCHandle dxHnd = GCHandle.Alloc( dx, GCHandleType.Pi nned);
GCHandle carHnd = GCHandle.Alloc( caret, GCHandleType.Pi nned);
GCHandle clsHnd = GCHandle.Alloc( clss, GCHandleType.Pi nned);
GCHandle glyHnd = GCHandle.Alloc( glys, GCHandleType.Pi nned);
try
{
GpcResults rs = new GpcResults();
rs.StructSize = Marshal.SizeOf( typeof(GpcResul ts));
rs.OutString = new String('\0', len + 2);
rs.Order = ordHnd.AddrOfPi nnedObject();
rs.Dx = dxHnd.AddrOfPin nedObject();
rs.CaretPos = carHnd.AddrOfPi nnedObject();
rs.Class = clsHnd.AddrOfPi nnedObject();
rs.Glyphs = glyHnd.AddrOfPi nnedObject();
rs.GlyphCount = len;
rs.MaxFit = 0;
GcpFlags flg = GcpFlags.FliMas k & GetFontLanguage Info(dev);
int r = GetCharacterPla cementW(dev, txt, len, 0, ref rs,
flg);
if (r == 0) // 0:Error; OK e.g. 0x100085
{
int err = Marshal.GetLast Win32Error();
// todo: error handling
}

return rs.OutString;
}
finally
{
ordHnd.Free();
dxHnd.Free();
carHnd.Free();
clsHnd.Free();
glyHnd.Free();
// e.Graphics.Rele aseHdc(dev);
}

}
}
}

Jan 19 '06 #2
Hi Asaf,
Based on the current situation, please help me to confirm some information
on your side: What exactly are you trying to get in the output? From my
experience, reordering Hebrew text follows the BIDI algorithm, there are no
rules for reordering English text.
This information will help us get closer to this issue, so I appreciate
your time in collecting it. Let me know the results at your earliest
convenience. If you have any questions or concerns, please let me know. I
am standing by to help you.

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

--------------------
Thread-Topic: Reorder English text?
thread-index: AcYc3HXu25f1659 dQkWEIFPxZsQ00A ==
X-WBNR-Posting-Host: 213.8.95.84
From: "=?Utf-8?B?QXNhZg==?=" <AG**@newsgroup s.nospam>
Subject: Reorder English text?
Date: Thu, 19 Jan 2006 01:41:02 -0800
Lines: 146
Message-ID: <CC************ *************** *******@microso ft.com>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 8bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GXA03.phx.gbl
Xref: TK2MSFTNGXA02.p hx.gbl microsoft.publi c.dotnet.langua ges.csharp:3796 30
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp

Hi,

Below is a calss with function I gathered from a news group that uses
GetCharacterPl acement API to reorder text.
I have mixed text Hebrew/English and the function reorders the Hebrew text.

I would like to reorder the English text instead the Hebrew text.

How can I do that please?

Regards,
Asaf ----------------------------------------------------------------------------
----------------
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Drawing;
using System.Runtime. InteropServices ;
using System.Windows. Forms;

namespace GetCharacterPla cement
{
class FlipHebrew
{
[StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Auto)]
public struct GpcResults // Win32: GCP_RESULTS
{
public int StructSize;
[MarshalAs(Unman agedType.LPTStr )]
public string OutString;
public IntPtr Order;
public IntPtr Dx;
public IntPtr CaretPos;
public IntPtr Class;
public IntPtr Glyphs;
public int GlyphCount;
public int MaxFit;
}
[Flags]
public enum GcpFlags // Win32: GCP_xxx flags, WinGDI.h
{
DBCS = 0x00000001,
ReOrder = 0x00000002,
UseKerning = 0x00000008,
GlyphShape = 0x00000010,
Ligate = 0x00000020,
Diacritic = 0x00000100,
Kashida = 0x00000400,
Error = 0x00008000,
Justify = 0x00010000,
FliGlyphs = 0x00040000,
ClassIn = 0x00080000,
MaxExtent = 0x00100000,
JustifyIn = 0x00200000,
DisplayZWG = 0x00400000,
SymSwapOff = 0x00800000,
NumericOverride = 0x01000000,
NeutralOverride = 0x02000000,
NumericsLatin = 0x04000000,
NumericsLocal = 0x08000000,
FliMask = 0x0000103B
}

[DllImport("gdi3 2.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern int GetCharacterPla cementW(IntPtr dev, string
text, int count, int max,
[In, Out] ref GpcResults results, GcpFlags flags);
[DllImport("gdi3 2.dll", ExactSpelling = true)]
public static extern GcpFlags GetFontLanguage Info(IntPtr dev);
public string funcGetCharacte rPlacement(stri ng sTextToFlip)
{
Panel pnl = new Panel();
Graphics g = pnl.CreateGraph ics();
IntPtr dev = g.GetHdc();

//string txt = "בדיקת עברית With English ועוד ×¢× ‘רית"; string txt = sTextToFlip;
int len = txt.Length;

int[] order = new int[len];
int[] dx = new int[len];
int[] caret = new int[len];
byte[] clss = new byte[len];
short[] glys = new short[len];
GCHandle ordHnd = GCHandle.Alloc( order, GCHandleType.Pi nned);
GCHandle dxHnd = GCHandle.Alloc( dx, GCHandleType.Pi nned);
GCHandle carHnd = GCHandle.Alloc( caret, GCHandleType.Pi nned);
GCHandle clsHnd = GCHandle.Alloc( clss, GCHandleType.Pi nned);
GCHandle glyHnd = GCHandle.Alloc( glys, GCHandleType.Pi nned);
try
{
GpcResults rs = new GpcResults();
rs.StructSize = Marshal.SizeOf( typeof(GpcResul ts));
rs.OutString = new String('\0', len + 2);
rs.Order = ordHnd.AddrOfPi nnedObject();
rs.Dx = dxHnd.AddrOfPin nedObject();
rs.CaretPos = carHnd.AddrOfPi nnedObject();
rs.Class = clsHnd.AddrOfPi nnedObject();
rs.Glyphs = glyHnd.AddrOfPi nnedObject();
rs.GlyphCount = len;
rs.MaxFit = 0;
GcpFlags flg = GcpFlags.FliMas k & GetFontLanguage Info(dev);
int r = GetCharacterPla cementW(dev, txt, len, 0, ref rs, flg); if (r == 0) // 0:Error; OK e.g. 0x100085
{
int err = Marshal.GetLast Win32Error();
// todo: error handling
}

return rs.OutString;
}
finally
{
ordHnd.Free();
dxHnd.Free();
carHnd.Free();
clsHnd.Free();
glyHnd.Free();
// e.Graphics.Rele aseHdc(dev);
}

}
}
}


Jan 23 '06 #3

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

Similar topics

18
5455
by: OrenFlekser | last post by:
Hi I've posted this message couple of days ago, but I can't find it now, so sorry if you see it twice... Anyways - I have a text box, and I want my users to be able to write only in english inside it. I want to prevent the Alt+Shift option of switching to other languages. Thanks alot - Oren
0
1376
by: Asaf | last post by:
Hi, I have a mixed text Hebrew/English and I would like to reorder just the English text. I was reading that this task can be done with GetCharacterPlacement API function but I don’t know how to deal with this function using C#. A code example will be much appreciated. Thanks in advanced,
3
8124
by: CodeRazor | last post by:
Is it possible to reorder items in a listbox server control by having the user select an item and then click an up or down button? ... how? Or is this something that can only be achieved client side? thanks
1
3899
by: Mat | last post by:
Reordering Column changes column Indexes???? i use column.index to access(or add ) data in listview. i want to allow user to reorder columns as they need. So i am afraid to get wrong data when user reorder columns. Can anyone confirm? Thanks you in advance. Mat
0
1267
by: uv507 | last post by:
Hello, I have found a way to easily reorder rows of my listview. But it only works in small icons mode. When I do my reordering (drag and drop in my own list) in large icons mode, the item that I wanted reorder is automatically send to the end of the listview... :(( Has someone got the same problem ??? Thanks in advance for your help
4
2627
by: Asaf | last post by:
Hi, For a particular system I need to transfer Hebrew text with encoding ISO-8859-8 and to flip only the English characters. For example the text: טקסט עברית With English ועוד עברית Should be transfer to the system as: טקסט עברית hsilgnE htiW ועוד עברית
0
2157
by: daju | last post by:
hello My question is, after we allow the column reorder can we modify the order of columns through our code. What I need to do is reorder the listview columns so the first column with the checkboxes switches position with the middle column(there are five columns in the listview)? Thank you in advance, D.
4
6113
by: rdraider | last post by:
Use the Northwind database Products table as an example. Purchasing dept gets a report showing when inventory items on hand qty are below the reorder level. easy enough: Select ProductID, ProductName, SupplierID, UnitsInStock, ReorderLevel from Products where (UnitsInStock < ReorderLevel) Results: ProductID ProductName SupplierID UnitsInStock ReorderLevel
3
1967
by: done4who | last post by:
Heres my problem: my javacript code reads each child element e.g.: <video> <author>skateboard2</author><id>xqWBGvbvw7g</id><title>zach skating</title><length_seconds>100</length_seconds></video> The order is author, id, title, length. I NEED to reorder to any I want title, author, length, id. When it reads in via javascript and each <childelement> is formatted via CSS using relative styling its is shows up incorrectly. I need to...
0
8367
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
8889
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
8570
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
8650
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...
0
7391
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.