Bug 2566 - Unable to use ShowTextAtPoint for text containing latin characters like Ä with either GetTextEncoding values
Summary: Unable to use ShowTextAtPoint for text containing latin characters like Ä wit...
Status: RESOLVED FEATURE
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-12-19 11:00 UTC by Vivek
Modified: 2011-12-19 13:22 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description Vivek 2011-12-19 11:00:34 UTC
It appears that the internal mapping "algorithm" has a bug in it, even for non-Latin characters.  For instance, if you use ShowTextAtPoint (Helvetica or Arial) using GetTextEncoding.FontSpecific for the string 
  CAR 
you get
  `^o
Indeed, for characters with int values < 128, everything is shifted by 29.  However, if the string consists of lower case letters
  car
you get
  Řê
So, it suggests that the code does have access to the Latin-1 glyphs, but something is not being mapped right (or I am simply doing something stupid!) because it looks like the int values are shift by 128, 55, and 120 respectively.

BTW: Although I am fairly good at things on the C# side of the world, I am quite new to MT, iOS, etc.  So there is a distinct possibility that I don't "get it"!  In which case, it would help a great deal if someone could tell me how I could output a string like Ångström on a CGBitmapContext using Arial.
Comment 1 Sebastien Pouliot 2011-12-19 11:13:31 UTC
That's a CoreGraphics issue/feature but you can use UIKit to display UFT8 text.
See http://stackoverflow.com/q/7280002/220643
Comment 2 Vivek 2011-12-19 13:22:05 UTC
Thanks Sebastien.

For others who stumble onto this "bug", here's the code that finally made it work for me (because I was getting "flipped" text using Sebatien's link).

foo(...)
{
  ...

  UIGraphics.PushContext (this.mBmpCtx);
  //--- select the color you want, e.g., red
  this.mBmpCtx.SetFillColor(1f,1f,0f,0f); 
  //--- "flip" coordinate space
  this.MoveOriginToTopLeftGrowingRightAndDown (); 
  //--- for "Arial Bold" you need to use "Arial-BoldMT"
  var font = UIFont.FromName ("Arial-BoldMT", fFontHt);
  using (var nsStr = new NSString ("Ångström"))	
  {
    nsStr.DrawString (new PointF (X, Y), font);
  }
  UIGraphics.PopContext ();		

  ...
}

public void MoveOriginToTopLeftGrowingRightAndDown()
{
  //--- flip and move the coordinate space to have the origin 
  //    at the top-left corner (as in Windows Graphics)
  CGAffineTransform at = CGAffineTransform.MakeIdentity();
  at.Scale (1,-1);
  at.Translate(0, this.mBmpCtx.Height);
  this.mBmpCtx.ConcatCTM (at);
}