FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour different fonts in the same cell xbrowse
Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
different fonts in the same cell xbrowse
Posted: Thu Jun 26, 2008 02:19 PM

Hello

I would like to show different fonts in the same cell with xbrowse.

I remember seing something like this from Otto, i have searched but couldn't find it

If anyone knows how we can acheive this,

Thanks for the help,

Richard

http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
different fonts in the same cell xbrowse
Posted: Thu Jun 26, 2008 02:21 PM

Ask to Otto

Best Regards, Saludos



Falconi Silvio
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
different fonts in the same cell xbrowse
Posted: Thu Jun 26, 2008 02:54 PM

Hello Richard,

I changed METHOD PaintData. I send a # as a prefix in my data string.
Then in the paintData method I check if the first character is # if yes I us another font.

It is hardcoded but for my task ok.

Regards,
Otto

IF left(cdata,1)="#"

  cLine = SubStr(ExtractLine( cData, @nFrom ),2)
  oFont1   := ::oFntGross

  oFont1:Activate( hDC )
  SetTextColor( hDC, aColors[ 1 ] )
  SetBkColor( hDC, aColors[ 2 ] )
  DrawTextEx( hDC, cLine ,;
              {nRow, nCol, nRow + oFont1:nHeight(), Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) },;
              ::nDataStyle )
  oFont1:Deactivate( hDC )


  cLine = Alltrim(SubStr(cData, nFrom ))
  oFont:Activate( hDC )

  SetTextColor( hDC, aColors[ 1 ] )
  SetBkColor( hDC, aColors[ 2 ] )

   //msginfo(oFont:nHeight())

   DrawTextEx( hDC, cLine,;
              {nRow+oFont1:nHeight(), nCol, nRow +oFont1:nHeight() + (oFont:nHeight())*2 + 5 , Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) },;
              ::nDataStyle )
     oFont:Deactivate( hDC )

else
oFont:Activate( hDC )
SetTextColor( hDC, aColors[ 1 ] )
SetBkColor( hDC, aColors[ 2 ] )
DrawTextEx( hDC, cData,;
{nRow, nCol, nRow + nHeight, Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) },;
::nDataStyle )
oFont:Deactivate( hDC )
ENDIF

Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
different fonts in the same cell xbrowse
Posted: Thu Jun 26, 2008 06:30 PM

Otto

Thank you

Richard :)

http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
different fonts in the same cell xbrowse
Posted: Fri Jun 27, 2008 04:25 PM
Otto's work is very nice. We observe that there are times need is felt to extend the drawing facilities natively provided by XBrowse. It is not always possible to accommodate all such requirements in a general way and even otherwise we may not be able to provide the facility within the time required. This is entailing change of source code. We thought we could make it easier by providing facility to allow the programmer to draw the text in the manner required, when needed.

We have provided a new DATA bPaintText in the TXBrwColumn class. If a codeblock is assigned to this data, this codeblock is called to paint the data in the cell. Details are givien in the Whatsnew.txt.

We give here an example of how to use this facility, in the above case.

Example:
#include 'fivewin.ch'
#include 'xbrowse.ch'

function main()

   local oDlg, oBrw
   local oFont, oBold, oItalic
   local aData    := {}

   DEFINE FONT oFont   NAME 'TAHOMA' SIZE 0,-12
   DEFINE FONT oBold   NAME 'TAHOMA' SIZE 0,-12 BOLD
   DEFINE FONT oItalic NAME 'TAHOMA' SIZE 0,-12 ITALIC

   AAdd( aData, { 1, 'Otto   ', ;
      'Mr.Otto' + CRLF + ;
      'deleveloped using multiple fonts in the same cell' } )
   AAdd( aData, { 2, 'Richard', ;
      "MR.OTTO'S" + CRLF + ;
      'work is well appreciated' } )
   AAdd( aData, { 3, 'Chidak ', ;
      'Mr.Richard Chidak' + CRLF + ;
      'also has  similar requirement. But needs to change the library' } )
   AAdd( aData, { 4, 'Antonio', ;
      'FWH' + CRLF + ;
      'Provides easier solution for owner drawing data without changing library code' } )

   DEFINE DIALOG oDlg SIZE 440,440 PIXEL FONT oFont

   @ 10, 10 XBROWSE oBrw ;
      HEADERS 'No', 'Name', 'Text' ;
      SIZE 200, 200 PIXEL ;
      OF oDlg ;
      ARRAY aData AUTOCOLS ;
      LINES

   oBrw:nStretchCol := STRETCHCOL_LAST

   WITH OBJECT oBrw:aCols[3]
      :nHeadStrAlign := AL_CENTER
      :nWidth        := 200
      :bPaintText    := { |oCol, hDC, cText, aCoord| DrawText( oCol, hDC, cText, aCoord, oBold, oItalic ) }
   END

   oBrw:nDataLines := 6
   oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTERED

   RELEASE FONT oFont
   RELEASE FONT oBold
   RELEASE FONT oItalic

return nil

static function DrawText( oCol, hDC, cText, aCoord, oBold, oItalic )

   local nTop  := aCoord[ 1 ], nLeft := aCoord[ 2 ]
   local nBottom := aCoord[ 3 ], nRight := aCoord[ 4 ]
   local nRow  := nTop
   local cLine, nFontHt, nAt

   nAt      := AT( CRLF, cText )
   if nAt > 0
      cLine    := Left( cText, nAt - 1  )
      oBold:Activate( hDC )
      nFontHt  := GetTextHeight( oCol:oBrw:hWnd, hDC )
      DrawTextEx( hDC, cLine, { nRow, nLeft, nRow + nFontHt + 4, nRight }, 1 ) //oCol:nDataStyle )
      oBold:DeActivate( hDC )
      nRow     += nFontHt + 4
      cLine    := SubStr( cText, nAt + 2 )

   else
      cLine    := cText
   endif

   oItalic:Activate( hDC )
   DrawTextEx( hDC, cLine, { nRow, nLeft, nBottom, nRight }, oCol:nDataStyle )
   oItalic:DeActivate( hDC )


return nil


Here is a screenshot of the result:


We welcome comments and feedback
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
different fonts in the same cell xbrowse
Posted: Fri Jun 27, 2008 05:51 PM

Antonio,

Very impressive!

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion