Right-to-left support for TAChart? lazarus / 55-TAChart ---------------------------------------------------------------------- wp · 2014-03-23 15:34 In another thread (http://forum.lazarus.freepascal.org/index.php/topic ,22881.msg135868.html#msg135868), there has been a discussion whether TAChart supports right-to-left mode. No, it does not, but my feeling is that it should not be too difficult to implement it. Before I begin thinking about the details let me ask some questions about right-to-left charts to users in Near-East: Will the horizontal axis be flipped, i.e. minimum at right, maximum at left?Would it be acceptable if right-to-left mode were available only at run-time? Or must it be available at design-time as well?Where is the y axis of a right-to-left chart? At the left? Or at the right?If at the right, would it be confusing if the y axis were still be called "LeftAxis" although it is drawn at the right?On the left axis in left- to-right, the axis title is rotated by 90 degrees counter-clockwise, i.e. the base of the characters points to the axis line. If the y axis is  at the right, does the base of the characters point to the axis line again (rotation angle 90 degrees clockwise)?If the y axis is at the right then the legend, by default, should be at the left?All text must be drawn from right to left, except for numbers which are always left-to-right? What if a number has a a text appendix? E.g., "1000 tons" in left-to-right will become "snot 1000" in right-to-left, or "1000 snot", or something else?Similar to the axis name: Some marks etc have an alignment property. When a text is left-aligned in left- to-right, will the property, in right-to-left, have to switch to taRightJustify, or could it at stay at taLeftJustify and the text just would be drawn in a right-justified way? ---------------------------------------------------------------------- Avishai · 2014-03-26 15:55 WP, I really want to answer all of your questions but I have been very sick and in hospital for 2 months and I just don't have the strength yet.  I will tell you that it should be R2L at design-time but I would make that a very low priority. As far as what is Left and what is Right graphically, just look at it in a mirror and you it will be correct. Setting BiDiMode:= bdRightToLeft seems to handle R2L Text correctly for most Lazarus controls on the Windows platforms. You can test to see by comparing your text with TEdit or TMemo. Calling "LeftAxis" the same would be consistent with Delphi/Lazarus like Control.Left refers to the Right. R2L Text Aligment doesn't work correctly in Lazarus anyway (RightJustify  gives the same result as LeftJustify) so until someone fixes that issue I wouldn't spend much time on it.  But with R2L text "Left" refers to Right and "Right" refers to Left. (MS Visual Studio calls them "X" and "Y" for that reason) I know this isn't much of an answer but it's the best I can do until I get my strength back and get off these medications. ---------------------------------------------------------------------- wp · 2014-03-26 22:14 QuoteI know this isn't much of an answer but it's the best I can do until I get my strength back and get off these medications.No that's enough. And first of all, get well soon. ---------------------------------------------------------------------- wp · 2014-03-29 18:11 Before I post the changes, is this implementation of BiDi mode in TAChart correct? -- See right chart of attached image. ---------------------------------------------------------------------- Avishai · 2014-03-29 18:22 Graphically it looks perfect to me.  If you want to try some Hebrew Text you can Copy/Paste my name.  אבישי!  But if it is correct for R2L it will show !אבישי (punctuation on the Left) ---------------------------------------------------------------------- wp · 2014-03-29 18:48 Thanks - I see that I'll have to dig deeper into the text drawing code of TAChart. I was just modifying positions etc, but did not tell the drawers to paint right-to-left. BTW: Is the text rotation of the y axis ok? ---------------------------------------------------------------------- Avishai · 2014-03-29 19:25 I'm not sure there is a "right" way for the "y axis" text.  But my personal preference would be for it to be readable from the Left side of the page.  In other words, rotated 180 deg from the way you have it now.  But as I said, that just my taste. Nice touch adding the TEdits to the form and setting BiDiMode.  It makes it so easy to verify that things are as they should be. ---------------------------------------------------------------------- wp · 2014-03-29 19:45 I found a "RightToLeft" property of the TTextStyle which is used by TCanvas for drawing text. If I set this to true the exclamation mark goes to the left. Unfortunately the standard TCanvasDrawer of TAChart which paints on TCanvas directly uses the TextOut method for painting which does not seem to respect TTextStyle. My question to the experts: Do I have to write my own TextOut based on TextRect which does respect TTextStyle? Or is there a simpler way? ---------------------------------------------------------------------- Avishai · 2014-03-29 20:03 I just noticed that you don't have any negative numbers showing.  For L2R it would show -0.5 but for R2L it would show 0.5- ---------------------------------------------------------------------- wp · 2014-03-29 20:08 Same issue... I'll have to solve that TextOut thing first, I am sure that when the Canvas knows about R2L it will be correct (in a label the negative number is drawn correctly). ---------------------------------------------------------------------- Blaazen · 2014-03-29 20:13 Quote Do I have to write my own TextOut based on TextRect which does respect TTextStyle? Or is there a simpler way?Themes should do the job. Method ThemeServices.DrawText and you have to add DT_RTLREADING to flags. ---------------------------------------------------------------------- wp · 2014-03-29 20:27 QuoteMethod ThemeServices.DrawText and you have to add DT_RTLREADING to flags.Is this cross-platform? The drawing engine of TAChart looks quite general to me, and I don't want to lose anything. ---------------------------------------------------------------------- Blaazen · 2014-03-29 20:48 QuoteIs this cross-platform?Yes. ---------------------------------------------------------------------- wp · 2014-03-29 22:47 Making progress, the CanvasDrawer seems to be working. Next step will be to have a look at the other drawing fontends like SVGDrawer, BGRADrawer, etc. @Blaazen: I finally decided to use Canvas.DrawText. Just a few lines -- adding ThemeServices would have been more work. ---------------------------------------------------------------------- wp · 2014-03-30 21:53 The current TAChart version in Lazarus trunk (rev 44555) supports BiDiMode now. Just set BiDiMode to bdRightToLeft to mirror the entire chart as can be seen in the screenshot of the previous posting. This occurs at designtime and, of course, at run time. The y axis is called automatically "right axis" in R2L. The special punctuation rules that Avishai mentioned above are obeyed by all drawers using a standard canvas. This means that screen output, copying to the clipboard, saving to standard bitmap files (also: wmf), and printing are working correctly. The special drawers for BGRAbitmap, OpenGL, fpvectorial etc are not fully tested, but usually do not support the correct text output so far (the layout of axes, titles, legend etc. is correct, though). ---------------------------------------------------------------------- Avishai · 2014-03-31 02:37 Nice job!  I only took a quick look at TAChart with BiDiMode:= bdRightToLeft.  I did find one very small problem. Property BottomAxis.Arrow.Visible:= True         Arrow points Right regardless of BiDiMode. ---------------------------------------------------------------------- wp · 2014-03-31 21:46 Fixed in rev 44568