473,743 Members | 2,247 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 3306
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
5461
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
1382
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 dont know how to deal with this function using C#. A code example will be much appreciated. Thanks in advanced,
3
8131
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
3916
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
1270
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
2632
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
2163
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
6128
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
1968
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
8970
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9486
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...
0
9344
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6763
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
6057
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4572
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
3286
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
2759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2195
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.