Print Page | Close Window

Question about rendering Text?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: General Discussion
Forum Description: Topics Related to Visual C++ MFC Development in General
URL: http://forum.codejock.com/forum_posts.asp?TID=7489
Printed Date: 25 June 2024 at 10:45pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Question about rendering Text?
Posted By: shobits1
Subject: Question about rendering Text?
Date Posted: 29 June 2007 at 9:09pm
Hello,,,
 
I have a question about how rendering text using codejock...
I search in the help but I didn't find anything, so if anybody know how I can use codejock to render Text please tell me how.
 
Note: I don't ask for general function that render text like TextOut|DrawText ... (I only ask for rendering text using codejock).
 
thank's for help.



Replies:
Posted By: Oleg
Date Posted: 30 June 2007 at 4:09am
Hi,
 
We don't have any special function for rendering text. What problem with CDC::DrawText  ?


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: shobits1
Date Posted: 30 June 2007 at 2:47pm
There is no problem, but I just wondered if there is special function in codejock.
 
thank's for replay


Posted By: shobits1
Date Posted: 02 July 2007 at 2:20am

I have a question about calculate the height of Text?

First I select a font object created previously
*/pdc->SelectObject( mFont );
 
then I used one of these function
1/pdc->GetTextMetrics(&TEXTMETRIC);
   then I use TEXTMETRIC.tmHeight
 
2/CSIZE = pdc->GetTextExtent( CString );
   then I use CSIZE.cy
 
3/pdc->DrawText( CString, CRectDT_CALCRECT );
 
but no one of them can return the right value of height.
 
Well, I wonder if you can help me....


Posted By: Oleg
Date Posted: 02 July 2007 at 5:01am
pdc->DrawText( CString, CRect, DT_CALCRECT ); have to return right value - check that rcHeight is 0 before you run it:
CRect rc(0, 0, nWidth, 0);


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: shobits1
Date Posted: 02 July 2007 at 5:45am
First I like to thanks oleg for his great help.
 
Look I don't know where I am wrong, this is my code:

VOID CCustomCaptionBar::DrawItem(LPDRAWITEMSTRUCT lpDrawIS)
{
 CDC *pdc = CDC::FromHandle(lpDrawIS->hDC);

 CRect rcClient; this->GetClientRect( &rcClient );
 CRect rcGradient(rcClient); rcGradient.bottom = rcGradient.top + this->m_cbGradientWidth;
 CRect rcSolid(rcClient); rcSolid.MoveToY(rcGradient.bottom); rcSolid.bottom-=rcGradient.bottom;

 XTPDrawHelpers()->GradientFill( pdc, rcGradient, this->m_clrGradientTop, this->m_clrGradientBottom, FALSE);

 pdc->FillSolidRect( rcSolid, this->m_clrBack );
 pdc->SetBkMode( TRANSPARENT );
 pdc->SetTextColor( RGB(255,0,0) );
 pdc->SelectObject( this->m_fntTitle );

 UINT nFormat = DT_BOTTOM|DT_SINGLELINE|DT_END_ELLIPSIS;//|DT_RIGHT;//*|DT_RTLREADING*/|DT_NOCLIP;//DT_INTERNAL
 this->m_rcTitle.SetRect(0,0,0,0);
 pdc->DrawText( this->m_strTitle, this->m_rcTitle, DT_CALCRECT );
 //Mybe I will use margin so I used
 this->m_rcTitle.MoveToXY( MarginX, MarginY ); <<=== It's this right. I have remove it for testing but it's the same
 pdc->DrawText( this->m_strTitle, this->m_rcTitle, nFormat );
}



Posted By: Oleg
Date Posted: 02 July 2007 at 8:46am

in line this->m_rcTitle.SetRect(0,0,0,0);

height have to be 0, but width have to be real width you need. try to replace to
 
 this->m_rcTitle.SetRect(0,0,rcClient.Width(),0);
 pdc->DrawText( this->m_strTitle, this->m_rcTitle, DT_SINGLELINE|DT_CALCRECT );
 


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: shobits1
Date Posted: 02 July 2007 at 5:01pm

Hi, It's the same; I have always extra large height then the text it self, look at this screenshoot:


if there any chance that the problem is with the font type I used. (I  use font from adobe common files, it is "WinSoft Serif Pro"  with extension ".otf" (open type font)).
this is the font files:

http://forum.codejock.com/uploads/20070702_165857_Fonts.rar - uploads/20070702_165857_Fonts.rar


In other hand this my class implementation


IMPLEMENT_DYNAMIC(CCustomCaptionBar, CCustomCaptionBarBase)

BEGIN_MESSAGE_MAP(CCustomCaptionBar, CCustomCaptionBarBase)
 ON_WM_SIZE()
END_MESSAGE_MAP()


CCustomCaptionBar::CCustomCaptionBar(CSize btnSize)

 //Some Initialization
 //...
 //..
 //.

 this->m_cbGradientWidth  = 30;
 this->m_clrGradientTop  = RGB(79, 131, 209);
 this->m_clrGradientBottom = RGB(255, 255, 255);
 this->m_clrBack   = RGB(255, 255, 255);

 this->m_nXMargeTitle = 10;
 this->m_nYMargeTitle = 10;

 m_strTitle = _T("قسم السنة الأولى أ");

 //this->m_fntTitle.CreatePointFont( 180, _T("WinSoft Serif Pro") );
 LOGFONT lf;
 ::ZeroMemory(&lf, sizeof(LOGFONT));

 lf.lfHeight = -MulDiv( 18, theApp.m_pSAMResource->m_LogPixelsY, 72 );
 lf.lfCharSet = ARABIC_CHARSET;
 lf.lfQuality = /*ANTIALIASED_QUALITY; //*/CLEARTYPE_QUALITY;
     ::STRCPY_S(lf.lfFaceName, LF_FACESIZE, _T("WinSoft Serif Pro") ); 
 
 this->m_fntTitle.CreateFontIndirect( &lf );


}

CCustomCaptionBar::~CCustomCaptionBar()
{
 this->m_fntTitle.DeleteObject();
}


VOID CCustomCaptionBar::DrawItem(LPDRAWITEMSTRUCT lpDrawIS)
{
 CDC  *pdc = CDC::FromHandle(lpDrawIS->hDC);

 CRect rcClient; this->GetClientRect( &rcClient );
 CRect rcGradient(rcClient); rcGradient.bottom = rcGradient.top + this->m_cbGradientWidth;
 CRect rcSolid(rcClient);  rcSolid.MoveToY(rcGradient.bottom); rcSolid.bottom-=rcGradient.bottom;

 XTPDrawHelpers()->GradientFill( pdc, rcGradient, this->m_clrGradientTop, this->m_clrGradientBottom, FALSE); 
 pdc->FillSolidRect( rcSolid, this->m_clrBack );

 pdc->SetBkMode( TRANSPARENT );
 pdc->SetTextColor( RGB(55,55,55) );
 pdc->SelectObject( m_fntTitle );
 UINT nFormat = DT_BOTTOM|DT_SINGLELINE|DT_END_ELLIPSIS;//|DT_RIGHT;//*|DT_RTLREADING*/|DT_NOCLIP;//DT_INTERNAL

 this->m_rcTitle.SetRect(0,0,rcClient.Width(),0);
 pdc->DrawText( this->m_strTitle, this->m_rcTitle, DT_SINGLELINE|DT_CALCRECT  );
 pdc->DrawText( this->m_strTitle, this->m_rcTitle, nFormat );
 pdc->FrameRect( this->m_rcTitle, &CBrush(RGB(255,0,0)) );

 CRect rcrc(this->m_rcTitle); rcrc.top = rcrc.bottom; rcrc.bottom ++;
         rcrc.left +=6; //rcrc.right = 200;
 XTPDrawHelpers()->GradientFill( pdc, rcrc, this->m_clrGradientTop, this->m_clrGradientBottom, TRUE); 
 
}

Note: I used arabic characters, and drawing from right to left; the application initialized first with (CWinApp)this->SetDefaultLayout( LAYOUT_RTL );



Posted By: Oleg
Date Posted: 03 July 2007 at 1:54am
Hello,
 
Code now looks good :( Problem can be indeed because of fonts. if you use predefined height of font you can use predefined height of this text line too....


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: shobits1
Date Posted: 03 July 2007 at 6:05am
I see,
 
thank you..


Posted By: shobits1
Date Posted: 04 July 2007 at 1:48pm

hi oleg, I finally figure it out and find some sort of solution....

I agree with you maybe the problem is in the font, but this is the solution I have found:

if I want to create Normal font with weight = FW_NORMAL then I must use:

to calculate the rect;
pdc->DrawText( strTitle, rcTitle, DT_VCENTER|DT_SINGLELINE|DT_CALCRECT ); //DT_VCENTER solve the problem of extra height

to draw
pdc->DrawText( strTitle, m_rcTitle, DT_BOTTOM|DT_SINGLELINE );


if I want to create Bold font with weight = FW_BOLD then simply use:

to calculate the rect;
pdc->DrawText( strTitle, rcTitle, DT_SINGLELINE|DT_CALCRECT );

to draw
pdc->DrawText( strTitle, m_rcTitle, DT_BOTTOM|DT_SINGLELINE );



Posted By: terrym
Date Posted: 27 August 2007 at 6:01am
There is a better option to rewrite the DrawText function as this is a very limited function as it works in integers and loses accuracy, therefore not giving WYSIWYG
 
We decided to write our own version which uses it's own kerning and works using floating point accuracy giving true WYSIWYG
 


-------------
Thank you,
Terry Mancey

email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net