| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi!
I'm working with Borland C++ Builder 6 and i need to get the mirror of a text; it means that a string has to be flipped. In other words, i don't need only that the characters of a string change order ('mirror' becomes 'rorrim'), but also the single font must be flipped (not using a mirrored font). How can i obtain that? I tried by inverting the order of the pixels of the Canvas in which the text is drawn, but in this way the software get too slow. Please, give me help! Thanks a lot Bye |
|
#2
|
|||
|
|||
|
Hi!
I found out the solution of this problem and i post it for people that must solve it! What you've got to do is to transform the way in which the canvas is drawn by a transformation matrix. You act like that: Above all define the handle that manage your canvas: HDC hDC; hDC = Canvas->Handle; Then you have to define the transformation matrix, that allow you to act two-dimensional linear transformation between world space and page space for the specified device context: XFORM xForm; xForm.eM11 = (FLOAT) -1; xForm.eM12 = (FLOAT) 0.0; xForm.eM21 = (FLOAT) 0.0; xForm.eM22 = (FLOAT) 1; xForm.eDx = (FLOAT) 0.0; xForm.eDy = (FLOAT) 0.0; This xForm cause the flip of the canvas on horizontal axis; that's why each point (x, y), after the transformation, become the new point (x', y') in the following way: x' = x * eM11 + y * eM21 + eDx, y' = x * eM12 + y * eM22 + eDy, where the transformation matrix is represented by the following: | eM11 eM12 0 | | eM21 eM22 0 | | eDx eDy 1 | be carefull about eDx e eDy, thinking of that the point (0, 0) of the canvas is the top-left angle. Now you have to set the graphics mode for the specified device context: SetGraphicsMode( hDC, GM_ADVANCED ); in that way you obtain the behaviour: Windows NT: Sets the advanced graphics mode that allows world transformations. This value must be specified if the application will set or modify the world transformation for the specified device context. In this mode all graphics, including text output, fully comforms to the world-to-device transformation specified in the device context. Windows 95: The GM_ADVANCED value is not supported. When playing enhanced metafiles, Windows 95 does its best to ensure that enhanced metafiles on Windows 95 look the same as they do on Windows NT. To accomplish this, Windows 95 may simulate GM_ADVANCED mode when playing specific enhanced metafile records. Then set the two-dimensional linear transformation between world space and page space for the specified device context (hDC): SetWorldTransform(hDC, &xForm); from now, each thing that you draw on the canvas is drawn transformed (by the transformation matrix xForm); in my case i'll get my mirrored text: Canvas->TextOut(-100, 100, "mirror"); to come back and draw normally, you have only to set the inver matrix: xForm.eM11 = (FLOAT) -1; xForm.eM12 = (FLOAT) 0.0; xForm.eM21 = (FLOAT) 0.0; xForm.eM22 = (FLOAT) 1; xForm.eDx = (FLOAT) 0.0; xForm.eDy = (FLOAT) 0.0; and continue with your code!!! What a rough thing!! Have a good work! Hi |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Mirror Text |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|