justify a text

justify a text

Postby Otto » Sat May 19, 2012 5:24 pm

For my "dear old friend" Silvio

Maybe my Metro Style Infobox is of any use for you.
Regards,
Otto


Code: Select all  Expand view  RUN

#define DT_WORDBREAK         16
function MetroMsgInfo2( cTitel, cAnzeige1 )

   local  lVar        := .f.
   local  oDlg, oBTNNaviWeiter
   local  nWidth      := GetSysMetrics( 0 )
   local  nHeight     := GetSysMetrics( 1 )
   local  nLine       := 0
   local  nRowSpace   := 20
   local  nRowOffset  := 20

   local  hOldFont
   local  nTop           := 0
   local  nLeft      := 0
   local  nBottom        := 0
   local  nRight         := nWidth
   *----------------------------------------------------------
   
    nLeft   := nWidth/7/2.05
    nHeight := (nHeight - 100)/ 3 * 2 - nLine
   
   nLine := 16
      DEFINE DIALOG oDlg ;
           TITLE "Auswahl" ;
            FROM 100, -6 ;
              TO nHeight, nWidth + 6 ;
           PIXEL ;
           STYLE nOr( DS_MODALFRAME, WS_POPUP ) ;
           COLOR CLR_WHITE, CLR_GREEN ;
            FONT Setup():oFntMedium


   nLine := 1
   @ nRowOffset * nLine , nLeft ;
      SAY cTitel ;
      OF oDlg ;
      PIXEL ;
      FONT Setup():oFntMetroGross ;
      COLOR CLR_WHITE, CLR_GREEN

   nLine   := 9
   nTop    := nRowOffset * nLine
   nBottom := nTop + 420/2.05
   nRight  := nLeft + nWidth/2

   *----------------------------------------------------------
   nLine := 9
   @ nRowOffset + nRowSpace * nLine, nLeft  ;
      FLATBTN oBTNNaviWeiter ;
      PROMPT "OK" ;
      FONT Setup():oFntMedium ;
      SIZE 76/2.05, ( 24 ) /2.05 ;
      OF oDlg ;
      ACTION ( lVar := .t., oDlg:End() ) ;
      COLOR CLR_GREEN, RGB( 210, 210, 210 )

   nLeft := nLeft * 2.05
   ACTIVATE DIALOG oDlg ;
          ON PAINT ( SetBkMode( oDlg:hDC, 1 ),;
          hOldFont := SelectObject( oDlg:hDC, Setup():oFntMetroCombo:hFont ),;
          SetTextColor( oDlg:hDC, CLR_WHITE ),;
          DrawTextEx( oDlg:hDC, cAnzeige1, {nTop, nLeft, nBottom, nRight }, DT_WORDBREAK ),;
          SelectObject( oDlg:hDC, hOldFont ) )

RETURN NIL
//--------------------------------------------------------------------


Image


Have you a function to justify a text of a say on a dialog
sample
#include "Fivewin.ch"
#include "constant.ch"

#define LIGHTCYAN nRGB( 203, 225, 252 )

Functiopn test()

Local nBottom := 20
Local nRight := 42
Local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
Local nHeight := nBottom * DLG_CHARPIX_H

DEFINE DIALOG oDlg ;
SIZE nWidth, nHeight PIXEL ;
TITLE 'Donazione' ;
GRADIENT { { 1,CLR_WHITE, LIGHTCYAN } } TRANSPARENT
oDlg:lHelpIcon := .F.
oDlg:nStyle := nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, 4 )

cMessage:= 'Per poter utilizzare il pacchetto è ora necessario indicare la Chiave di Attivazione Procedura. La versione gratuita '+;
'del programma non permette la stampa dei listati, sarà possibile usare la procedura in modo dimostrativo '+;
'non nella completezza delle sue funzionalità. Premi Attiva per indicare la chiave di attivazione. ';

@ 50, 50 SAY oSay VAR cMessage OF oDlg FONT oFont PIXEL

Activate dialog oDlg
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: justify a text

Postby antolin » Thu May 24, 2012 6:28 am

Did you searching that:

viewtopic.php?f=6&t=19174
Peaaaaaso de foro...
FWH 2007 - xHarbour - BCC55
antolin
 
Posts: 498
Joined: Thu May 10, 2007 8:30 pm
Location: Sevilla

Re: justify a text

Postby ukoenig » Thu May 24, 2012 10:31 am

Antolin,

thank You very much for the nice function.
I have done some small changes, to make it more flexible.
As well changes needed, to use big fonts.

LOCAL cText := ;
'Word-1 Word-2 Word-3 Word-4 Word-5 Word-6 Word-7 Word-8 Word-9 '+;
'Word-10 Word-11 Word-12 Word-14 Word-15 Word-16 Word-17 Word-18 '+;
'Word-19 Word-20 Word-21 Word-22 Word-23 Word-24 Word-25 Word-26'

DEFINE FONT oFont NAME "Arial" SIZE 0,-24 BOLD

Image

I will create a little painter with frame autoadjust, testing fonts and colors, variable linespaces ...

First results !!!

Image

Any Brush and Text-Color :

Image

A Image :

Image

Maybe a Border needed ?:

Image

Image on Image with splitted Text :

Image

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: justify a text

Postby ukoenig » Fri May 25, 2012 6:56 pm

Hello Otto,

I had a look at Your function, but it does just a WORDBREAK no textadjust.
Also the function I'm just testing, doesn't work 100 % because it just includes
blanks, to make shorter lines equal to the longest line.
The only way will be, to change the font char-width of a line to adjust to the needed length.

Image

End of Line of Your Test :

Image

Best regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: justify a text

Postby Otto » Fri May 25, 2012 7:19 pm

Hello Uwe,
thank you. As I am totally focused on metro style I didn’t care about text adjust.
I found this Design Guidelines for Windows 8 Metro apps.
http://msdn.microsoft.com/en-us/library/windows/apps/hh464920.aspx

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: justify a text

Postby antolin » Thu May 30, 2013 4:55 pm

ukoenig, perdona por la tardanza, pero he estado muy liado y, la verdad, es que no he vuelto a utilizar esta función hasta hace poco, por lo que no pude comprobar que efectivamente hay situaciones en que el texto no se justifica bien, pero ya lo he solucionado.

En el post:

viewtopic.php?f=6&t=19174

Cambia la función FormatText por esta otra muy similar:

Code: Select all  Expand view  RUN
FUNCTION FormatText(oDlg,oFont,cText,nAncho)   // SEPARA EL TEXTO EN LINEAS
   LOCAL cTrozo,cLinea,lFinLin                 // Y LAS GUARDA EN UN ARRAY
   LOCAL aTexto := {}
   LOCAL nCrlf  := 0
   LOCAL nTokn  := 0
   LOCAL hDc    := oDlg:GetDc()
   LOCAL nChar  := Int(nAncho/GetTextWidth(hDc,"B",oFont:hFont))
   *
   DO WHILE !Empty(cText)
      lFinLin := .F.
      cLinea  := ""
      nTokn := 0
      *
      cTrozo  := StrToken(cText,1)
      IF Left(cTrozo,2) = CRLF
         cText  := SubStr(cText,3)
         cTrozo := ""
         lFinLin := .T.
      ENDIF
      IF GetTextWidth(hDc,cTrozo,oFont:hFont) > nAncho
     cLinea := Left(cTrozo,nChar)
     cText  := STUFF(cText,1,LEN(cLinea),"")
     cTrozo := ""
      ENDIF
      *
      DO WHILE !Empty(cTrozo) .AND. !Empty(cText)
         cTrozo := StrToken(cText,1)
         nCrLf  := AT( CRLF, cTrozo )
         IF nCrLf > 0
            cTrozo  := Left(cTrozo,nCrLf-1)
            lFinLin := .T. //  <------------  FIN DE PARRAFO
         ENDIF
         *
         IF GetTextWidth(hDc,cLinea+cTrozo,oFont:hFont) > nAncho
        IF GetTextWidth(hDc,cTrozo,oFont:hFont) > (nAncho*0.4)
           cLinea := Left(cLinea+" "+cTrozo,nChar)
           cText  := STUFF(cText,1,LEN(cLinea),"")
        ENDIF
        lFinLin := .F. //  <------------  NO FIN DE PARRAFO
        cTrozo  := ""
         ELSEIF lFinLin
            cText := STUFF(cText,1,LEN(cTrozo)+2,"")
            cLinea += cTrozo
        cTrozo := ""
            ++nTokn
         ELSE
            cText := LTRIM(STUFF(cText,1,LEN(cTrozo),""))
            cLinea += cTrozo+" "
            ++nTokn
         ENDIF
     *
     IF Empty(cText)    // LA ULTIMA LINEA SIEMPRE HA DE SER FIN DE PARRAFO
        lFinLin := .T.
     ENDIF
      ENDDO
      *
      AADD( aTexto, {RTRIM(cLinea),nTokn,lFinLin} )
   ENDDO
   oDlg:ReleaseDc()
RETURN aTexto


Espero que te funciones.

Un saludo
Peaaaaaso de foro...
FWH 2007 - xHarbour - BCC55
antolin
 
Posts: 498
Joined: Thu May 10, 2007 8:30 pm
Location: Sevilla

Re: justify a text

Postby James Bott » Fri May 31, 2013 1:31 am

Otto,

Well, I'm confused. Are you saying the the Metro Guidelines say to right justify? It appears that they say not to right justify.

6. Use kerning, tracking, hyphenation, and alignment effectively

As any type designer will tell you, the space between letters is just as important as the letter shapes. Kerning (mentioned in the first rule), applies spacing adjustments between specific pairs of letters to improve the letter spacing. We recommend that you apply it to all of your content.

Tracking, on the other hand, adds (or removes) space between all the letters in a string equally. As a font’s default letter spacing is often optimized for readability at a particular size, there are times when it might be appropriate to slightly widen the spacing. Tracking values of .01em or .02em may be helpful.

Using justified text makes it difficult to have good spacing. When text is forced to fit a container through justification, its spacing always suffers. Justified text usually has "rivers" of white space (large gaps between words) running through the content. Avoid fully-justified text and stick with left alignment whenever possible, and apply hyphenation to keep the right edge of the text from appearing too ragged.

http://msdn.microsoft.com/en-us/library ... 53415.aspx


Tracking, I believe, is referring to slightly adding to the kerning in certain situations (nothing to do with right justifying).

Maybe I am misunderstanding...

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: justify a text

Postby James Bott » Fri May 31, 2013 2:19 am

Otto,

I re-read the thread and now I get it. You were talking about left-justifying multi-line text in a SAY. Others posted about right-justifying--thus my confusion.

Your example is not compiling due to the missing setup() function. Could we get that?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: justify a text

Postby James Bott » Sat Jun 01, 2013 1:18 am

Otto,

This brings up an issue that I have been meaning to post about. The current TMetropanel and TMetrobutton are only useful for emulating the Windows 8 start screen. Windows 8 apps need much more flexibility such as different button sizes and different alignment. I note that the metrobutton class already has a drawMulitline() method but it depends on CRLF's already in the string. It would be very useful to have a method that would handle long strings automatically similar to your routine.

Otto, I am curious as to how you are building metro style apps without these classes?

I will start another topic about metro app design. I am very interested in this.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: justify a text

Postby Otto » Mon Jun 03, 2013 9:30 am

Dear James,
Setup() is a function I initially got from you and I use now everywhere.
In this case I only ask the FONT and size.

DEFINE FONT ::oFntMetroMedium NAME cFontName SIZE 0,-26 * ::nFaktor
I calculate a factor for different screen resolutions. As I code all Dialogs “hardcoded” I use the factor for example like this:
nRowOffset := 20 * nFaktor
nRowSpace := 20 * nFaktor
nLine := 2
@ nRowOffset + nRowSpace * nLine, nWidth/5/2.05 * nSpalte;
COMBOMETRO oCbx ;
VAR cCombo ;
PROMPTS aItems ;
OF oDlg ;


I am very confused about Metro. You only read negative news. Users do not like, Start button comes back, …

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: justify a text

Postby Otto » Mon Jun 03, 2013 9:33 am

Dear James,
… BTW, do you know how you can insert a desktop connection in WINDOWS 8 to start metro style Internet explorer or other RT programs.
Best regrads,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: justify a text

Postby James Bott » Mon Jun 03, 2013 1:26 pm

Otto,

I am very confused about Metro. You only read negative news. Users do not like, Start button comes back, …


Yes, there is a lot of complaining. However, there has been for every new version of Windows. And if we listened to all the negative feedback, we would all still be using DOS.

Also, I note that in general, I find most feedback (on anything) is negative. Happy customers don't spend the time to write up positive feedback like unhappy ones.

This is not to say that negative feedback can't be useful, because sometimes it is warranted.

I also find that most users cannot design good user interfaces (lots of programmers can't either). It takes a lot of real effort and lots of trial and error to come up with good user interfaces.

I see that the largest reason for Microsoft's implementation of Windows 8's new interface is an attempt to provide a similar interface on all devices--PC's, tablets, and phones. Of course, this may require some compromises.

I do not yet have a Windows 8 computer so I have not spent much time with it and I do not really have an opinion. Nevertheless, we programmers have to go with what is available, so we have to go with Windows 8 eventually.

IMHO.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: justify a text

Postby cnavarro » Mon Jun 03, 2013 1:36 pm

James, totally agree
My experience with Windows 8 is very good, it is fast and does not give any problem
regards

James, totalmente de acuerdo
Mi experiencia con Windows 8 es muy buena, es rápido y no da ningun problema
Saludos
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 18 guests

cron