Still not grasped encoding issues

Thanks to forum help last week I thought I was sorted on displaying the UK currency symbol correctly in a string. I decided to update an old program and the wrong output from my ‘new found knowledge’ is shown below;

174 @ £21.58=£3,754.92

The code to build this is;

curr=defineencoding(format(cdbl(txtPC1.text),"\\###,###.00"),Encodings.UTF8) output=defineEncoding(fldPC1.text+" @ "+format(ratenormal,"\\##.00")+"="+format(cdbl(txtPC1.text),"\\###,###.00"),encodings.UTF8)

I am formatting txtPC1.text as a currency number, it just reads 3754.92.

curr is a string as is output
ratenormal is a number constant

the output on the .pdf report I am generating should be;

174 @ 21.58=3,754.92

Am i missing something obvious?

You should use ConvertEncoding.

DefineEncoding is for incoming data (from files, databases, tcpsockets, etc.).
ConvertEncoding is for outgoing data (to files, databases,…).

Thanks for the reply Eli but the result is the same, line still shows as;

174 @ £21.58=£3,754.92

with the code as;

curr=convertencoding(format(cdbl(txtPC1.text),"\\###,###.00"),Encodings.UTF8) output=convertEncoding(fldPC1.text+" @ "+format(ratenormal,"\\##.00")+"="+format(cdbl(txtPC1.text),"\\###,###.00"),encodings.UTF8)

Do you need to change the encoding at all? Have a look at txtPC1.text and and fldPC1.text in the debugger. Then build your curr value piece by piece while checking the encoding.

I am getting closer. The ‘output’ string looks correct in the debugger. I am using (as its an old project) ‘fpdf’, which is fine. The encoding issue seems to be internal to this so I am just looking trhough the code to see how it defines the encoding it uses.

Hmm, no joy there, the constructor in fpdf defines UTF8.

fpdf doesn’t use UTF8 as far as I know.

It has the below snippet in the constructor which talks about encoding?

  //Standard fonts
  me.CoreFonts = new Collection
  me.CoreFonts.Add "Courier","courier"
  me.CoreFonts.Add "Courier-Bold","courierB"
  me.CoreFonts.Add "Courier-Oblique","courierI"
  me.CoreFonts.Add "Courier-BoldOblique","courierBI"
  me.CoreFonts.Add "Helvetica","helvetica"
  me.CoreFonts.Add "Helvetica-Bold","helveticaB"
  me.CoreFonts.Add "Helvetica-Oblique","helveticaI"
  me.CoreFonts.Add "Helvetica-BoldOblique","helveticaBI"
  me.CoreFonts.Add "Times-Roman","times"
  me.CoreFonts.Add "Times-Bold","timesB"
  me.CoreFonts.Add "Times-Italic","timesI"
  me.CoreFonts.Add "Times-BoldItalic","timesBI"
  me.CoreFonts.Add "Symbol","symbol"
  me.CoreFonts.Add "ZapfDingbats","zapfdingbats"
  
  //gdf: build chartable strings used in LoadCharTable
  me.kCTs = New Dictionary
  me.kCTs.Value("courier") = kCT_courier
  me.kCTs.Value("helvetica") = kCT_helvetica
  me.kCTs.Value("helveticab") = kCT_helveticab
  me.kCTs.Value("helveticabi") = kCT_helveticabi
  me.kCTs.Value("helveticai") = kCT_helveticai
  me.kCTs.Value("symbol") = kCT_symbol
  me.kCTs.Value("times") = kCT_times
  me.kCTs.Value("timesb") = kCT_timesb
  me.kCTs.Value("timesbi") = kCT_timesbi
  me.kCTs.Value("timesi") = kCT_timesi
  me.kCTs.Value("zapfdingbats") = kCT_zapfdingbats
  
  //gdf: set default encoding
  me.InternalEncoding = Encodings.UTF8

fpdf does not support UTF8, see fpdf.rbbas (code starting at line 2010):

Sub SetEnconding(enc as textEncoding) //gdf: set the string encoding used internally by rsFPDF //note that FPDF does not support UTF, but this method allows //to convert to other encodings, such as WindowsLatin1 //(Windows 1252, with Euro sign) or //ISOLatin9 (ISO 8859-15, with Euro sign) me.InternalEncoding = enc End Sub

Thanka Eli, I’ll have a play but may do a more extensive rewrite than i intended and use my dynapdf, or even just pop it into Word before printing.

[quote]curr=format(cdbl(txtPC1.text),"\£###,###.00")
[/quote]
Let’s unwrap your code a little. Strings that Xojo creates will be UTF8 by default, so working from the inside out

txtPC1.text // should be UTF8, but it doesn’t matter because you’re just going to convert it to a number
cdbl(txtPC1.text) // produces a number
format(cdbl(txtPC1.text),"\£###,###.00") // this string will be UTF8

So you see that neither DefineEncoding or ConvertEncoding to UTF8 will have any effect on the string, since it is already UTF8 to begin with. However, Eli is correct, you need to ConvertEncoding to the encoding that fpdf expects. Try Encodings.WindowsANSI or Encodings.ISOLatin9.

[quote] output=fldPC1.text+" @ “+format(ratenormal,”\£##.00")+"="+format(cdbl(txtPC1.text),"\£###,###.00")
[/quote]
Again, looking at the pieces

fldPC1.text // UTF8
" @ " // UTF8
format(ratenormal,"\£##.00") // UTF8
“=” // UTF8
format(cdbl(txtPC1.text),"\£###,###.00") // UTF8, as seen above

The combination of these strings will again be UTF8, but must be converted to the encoding used by fpdf.