
#TEXT ENCODING CONVERT CODE#
(It can represent certain other Windows code pages on other systems.) This is essentially an extension of the ASCII character set in that it includes all the ASCII characters with an additional 128 character codes. It is more properly referred to as Windows-1252 on Western/U.S. _ ANSI encoding is a slightly generic term used to refer to the standard code page on a system, usually Windows. I even tried to run the lisp via P/Invoke, but there were no visible results.Hello recently I had the same problem, and found that you can use this code: Windows-1252, it will work just like the ANSI, when generating a file you will see that the encoding format will be ANSI if you use that code,I refer to this text that I found in stackoverflow. NET function results in problems while the lisp function is OK. One more problem is changing a text s style from a Unicode font to a ANSI one. The problem is DBText.TextString always returns a Unicode string, seemingly irrespective of the string's encoding in the Autocad database, whereas, to do the same processing the lisp does, I need the ANSI chars, as Autocad sees it.ĭo you know of a way to get the string as Autocad sees it and not converted to unicode in an encoding I don't controll? The lisp function I posted does just that (it looks for a certain range of chars). It works OK, except it makes the hardcoded assumption that the source string is Unicode Latin.Īmong other things it means that running the code twice in succession on the same text results in gibberrish.Īs the program I write is not interactive, it blindly processes all texts ant therefore it needs to know beforehand if the text's encoding has to be converted. NET helps the conversion to become easier. I did try many different ways to encode the text to Hebrew letters and could not find the rule to make mathematic calculations. The ASCII number of characters in the previous code does not help when they are extended Unicode characters. String hebrewText = hebrewEncoding.GetString(latinBytes) Public static string ConvertLatinToHebrew(string latinText)Įncoding latinEncoding = Encoding.GetEncoding("Windows-1252") Įncoding hebrewEncoding = Encoding.GetEncoding(862) // MS-DOS Hebrewīyte latinBytes = latinEncoding.GetBytes(latinText) String hebrewText = ConvertLatinToHebrew(latinText) Public static void ConvertLatinToHebrewTest() Var text = (DBText)trans.GetObject(id, OpenMode.ForWrite) PromptEntityResult result = editor.GetEntity(peo) Peo.AddAllowedClass(typeof(DBText), true) Peo.SetRejectMessage("\nSelect only text") Var peo = new PromptEntityOptions("Select a text: ") Using (Transaction trans = db.TransactionManager.StartTransaction()) Public static void ConvertLatinToHebrew()ĭocument doc = NET framework does a great job on conversion. Here is the code to convert your texts from Unicode Latin to Hebrew. If you run the lsip routine, it fixes things, while in C# I fail. The drawing contains three copies of the same text, each one based on a differrent font.Īs you can see, the original text, based on the old font is legible, the other two are not because of the missing 0圆0 shift. I attach a sample drawing and the two relevant. I tried using differrent encodings, and the byte array obtained from the string varies with the encoding, sometimes arratically. I think the framework does some behind-the-scenes guesswork based on the system code page maybe, which alters the string returned by DBText.TextString, while lisp returns the raw chars. I'm trying to just add 0圆0 to each char between 0x80 and 0x9a.Ĭuriously enough, the following lisp code works and the result is as expected: This is basically just what i'm doing and it surely doesn't work. It seems that TextString forces the extended ASCII to Unicode and doing a poor job. The following is the kind of string DBText.TextString returns on the original text object (it should be Hebrew, but it's obviously not): I have a lisp function which performs the needed conversion by adding 0圆0 to each character value, but, while it works fine in lisp, it fails in C#.īTW, if I change the text font to a Windows font, it will display the same gibberish and only after running the lisp function mentioned above will it display correctly and then, of course, the extracted string will be OK too. Tried everything to convert the string, without success. Now if I try extracting the DBText.TextString of the text object, I get gibberish. The texts display fine in R2004 and above. The codes are from 0x80 thru 0x9a for the 26 Hebrew letters. shx font, with extended codes for the Hebrew alphabet. I have some legacy drawings with texts using alegacy. AutoCAD Mechanical : Insert PartReference and list PartReference in BOM 2.
