# cdCanvasSetTextAlignment

Definition: | include pGUI.e cdCanvasSetTextAlignment(cdCanvas canvas, integer alignment) -- or -- integer alignment = cdCanvasGetTextAlignment(cdCanvas canvas)
Description: | Defines the vertical and horizontal alignment of text. alignment: one of CD_NORTH, CD_SOUTH, CD_EAST, CD_WEST, CD_NORTH_EAST, CD_NORTH_WEST, CD_SOUTH_EAST, CD_SOUTH_WEST, CD_CENTER, CD_BASE_RIGHT, CD_BASE_LEFT, CD_BASE_CENTER. Default value: CD_BASE_LEFT (==CD_SOUTH_WEST).
pwa/p2js: | Supported. However note the (minor) discrepancy detailed in the technicalia. Replaced by the align parameter of gCanvasText() in xpGUI (and/or one day perhaps a TEXTALIGN attribute).
Description: | The following diagram illustrates for all 12 settings (or technically 9 as per the dropdown below) where the text will be drawn relative to a specified x,y position as indicated by the six asterisks: When translating C code, cdCanvasTextAlignment() must have Set/Get inserted. The old school cdTextAlignment() routine that did not need an explicit canvas is apparently no longer operational (as of IUP version 3.25, not my call or decision, and not that it bothers me much).
Technicalia | As far as I can tell, CD_BASE_(LEFT|CENTER|RIGHT) and CD_SOUTH(_WEST|""|_EAST) achieve the same effect, although they are not defined like that, at least not on desktop/Phix. The pwa/p2js re-implementation maps the enumeration to separate textAlign and textBaseline settings, and hence the reconsititution in cdCanvasGetTextAlignment() could potentially introduce some inconsistencies since it would be unable to distinguish between them. To minimise any such potential differences, in pGUI.js the CD_BASE_XXX are defined with the same values as the cardinal directions, which would probably only ever come to light in debugging statements (which you probably shouldn’t be doing in a browser anyway). In other words, `?{CD_BASE_LEFT,CD_BASE_CENTER,CD_BASE_RIGHT}` prints {9,10,11} on desktop/Phix but {7,1,6} under pwa/p2js, otherwise `?{CD_SOUTH_WEST,CD_SOUTH,CD_SOUTH_EAST}` is equivalent and totally consistent on both. There are no such overlapping/confusing CD_BASE_* settings in xpGUI, only the cardinal direction ones. Of course I could easily change pGUI.e to match pGUI.js, but slightly reluctant in case there’s something I’ve missed. (One obviously possibile failure might be a test/demo program that explicitly uses 0..11 instead of 0..8 or the named constants.) Likewise the default value should probably be CD_SOUTH_WEST rather than CD_BASE_LEFT, not that I could easily change that. Mind you, there are plenty of other such constant values that differ (slightly) between desktop/Phix and pwa/p2js, eg colours. It is a completely different underlying system after all, this one apparently just hit a nerve or something.