get font from HDC

Hi,

I would like to modify a function used to render some HTML and use the 
font I have choosen :


// C functions
int __stdcall DrawHTML(
                        HDC     hdc,        // handle of device context
                        LPCTSTR lpString,   // address of string to draw
                        int     nCount,     // string length, in characters
                        LPRECT  lpRect,     // address of structure with 
formatting dimensions
                        UINT    uFormat     // text-drawing flags
					   )
{
....


/* get the "default" font from the DC */
	SavedDC = SaveDC(hdc);
	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
	SelectObject(hdc, hfontBase);
	/* clear the other fonts, they are created "on demand" */
	for (Index = 0; Index < FV_NUMBER; Index++)
		hfontSpecial[Index] = NULL;
	hfontSpecial[0] = hfontBase;
....
}


Here is my code :


void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
BOOL bSelected)
{

  CFont* pOldFont  = MemDC.SelectObject( &m_font );

DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
			&rc,DT_LEFT|DT_WORDBREAK);
}



My problem is I don't know how to modify DrawHTML to take the font 
specified in DrawItem because from what I understand DrawHTML is using a 
default font :

hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
	SelectObject(hdc, hfontBase);











0
8/20/2007 1:05:43 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
800 Views

Similar Articles

[PageSpeed] 19

Oups I wanted to say (MemDC instead of pDC):

void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
BOOL bSelected)
{

  CFont* pOldFont  = MemDC.SelectObject( &m_font );

DrawHTML(MemDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
             &rc,DT_LEFT|DT_WORDBREAK);
}


mosfet a �crit :
> Hi,
> 
> I would like to modify a function used to render some HTML and use the 
> font I have choosen :
> 
> 
> // C functions
> int __stdcall DrawHTML(
>                        HDC     hdc,        // handle of device context
>                        LPCTSTR lpString,   // address of string to draw
>                        int     nCount,     // string length, in characters
>                        LPRECT  lpRect,     // address of structure with 
> formatting dimensions
>                        UINT    uFormat     // text-drawing flags
>                        )
> {
> ...
> 
> 
> /* get the "default" font from the DC */
>     SavedDC = SaveDC(hdc);
>     hfontBase = (HFONT)SelectObject(hdc, 
> (HFONT)GetStockObject(SYSTEM_FONT));
>     SelectObject(hdc, hfontBase);
>     /* clear the other fonts, they are created "on demand" */
>     for (Index = 0; Index < FV_NUMBER; Index++)
>         hfontSpecial[Index] = NULL;
>     hfontSpecial[0] = hfontBase;
> ...
> }
> 
> 
> Here is my code :
> 
> 
> void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
> BOOL bSelected)
> {
> 
>  CFont* pOldFont  = MemDC.SelectObject( &m_font );
> 
> DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
>             &rc,DT_LEFT|DT_WORDBREAK);
> }
> 
> 
> 
> My problem is I don't know how to modify DrawHTML to take the font 
> specified in DrawItem because from what I understand DrawHTML is using a 
> default font :
> 
> hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>     SelectObject(hdc, hfontBase);
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
0
8/20/2007 1:11:00 PM
On Mon, 20 Aug 2007 15:05:43 +0200, mosfet <john.doe@anonymous.org> wrote:

>Hi,
>
>I would like to modify a function used to render some HTML and use the 
>font I have choosen :
>
>
>// C functions
>int __stdcall DrawHTML(
>                        HDC     hdc,        // handle of device context
>                        LPCTSTR lpString,   // address of string to draw
>                        int     nCount,     // string length, in characters
>                        LPRECT  lpRect,     // address of structure with 
>formatting dimensions
>                        UINT    uFormat     // text-drawing flags
>					   )
>{
>...
>
>
>/* get the "default" font from the DC */
>	SavedDC = SaveDC(hdc);
****
You do a SaveDC but not a RestoreDC?  
****
>	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>	SelectObject(hdc, hfontBase);
****
It would be easier to write
	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
and not worry about the SelectObject pair
****
>	/* clear the other fonts, they are created "on demand" */
>	for (Index = 0; Index < FV_NUMBER; Index++)
>		hfontSpecial[Index] = NULL;
>	hfontSpecial[0] = hfontBase;
****
Note that if, in between times, the font which is currently selected into the DC is
deleted, the old handle you have saved here will become meaningless.  Therefore, you
cannot rely on the fact that this handle will still be valid at the time you use it.
Better to do an array of LOGFONT values, rather than an array of HFONTs.
****
>...
>}
>
>
>Here is my code :
>
>
>void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
>BOOL bSelected)
>{
>
>  CFont* pOldFont  = MemDC.SelectObject( &m_font );
>
>DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
>			&rc,DT_LEFT|DT_WORDBREAK);
****
So why do you save the font in the MemDC when you don't actually use it?  Note that the
m_font handle must represent a valid font to be selected, but the line seems to have no
meaning as shown in this function.  I would also suggest something like
	HDC dc = pDC->GetSafeHdc();
	if(dc == NULL)
	    return;
               DrawHTML(dc, ...as above...);
>}
>
>
>
>My problem is I don't know how to modify DrawHTML to take the font 
>specified in DrawItem because from what I understand DrawHTML is using a 
>default font :
>
>hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>	SelectObject(hdc, hfontBase);
>
****
I don't see the relationship of the above code to the problem.  Where is this line of
code?  I also could not find any method called DrawHTML in the MSDN documentation, could
you say more about where it is implemented or what it is supposed to do?
					joe
****
>
>
>
>
>
>
>
>
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
8/20/2007 1:20:59 PM
Actually I want to use the following control 
http://www.codeproject.com/listctrl/html_listctrl.asp (on Smartphone but 
that's not the question) that is a Custom CListCtrl deriving from CWnd.
It's appropriate because on smartphone you don't have much space and 
this listctrl allow to have a different size for each row in addtion to 
support a few HTML tags.

But when reading the code I saw that it uses hfontBase = 
(HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT)); and I 
think it would be better to use the font selected in the control.
For instanc I could do a SetFont on my listctrl and the DrawHTML 
function should use it to do its rendering (bold, italic, ...)



About savedc and restordc it's because I haven't posted all the code.

int __stdcall DrawHTML(
                        HDC     hdc,        // handle of device context
                        LPCTSTR lpString,   // address of string to draw
                        int     nCount,     // string length, in characters
                        LPRECT  lpRect,     // address of structure with 
formatting dimensions
                        UINT    uFormat     // text-drawing flags
					   )
{
	LPCTSTR Start;
	int Left, Top, MaxWidth, MinWidth, Height;
	int SavedDC;
	int Tag, TokenLength;
	HFONT hfontBase, hfontSpecial[FV_NUMBER];
	int Styles, CurStyles;
	SIZE size;
	int Index, LineHeight;
	POINT CurPos;
	int WidthOfSPace, XPos;
	BOOL WhiteSpace;
	RECT rc;
	
	if (hdc == NULL || lpString == NULL)
		return 0;
	if (nCount < 0)
		nCount = _tcslen(lpString);
	
	if (lpRect != NULL) {
		Left = lpRect->left;
		Top = lpRect->top;
		MaxWidth = lpRect->right - lpRect->left;
	} else {
		GetCurrentPositionEx(hdc, &CurPos);
		Left = CurPos.x;
		Top = CurPos.y;
		MaxWidth = GetDeviceCaps(hdc, HORZRES) - Left;
	} /* if */
	if (MaxWidth < 0)
		MaxWidth = 0;
	
	/* toggle flags we do not support */
	uFormat &= ~(DT_CENTER | DT_RIGHT | DT_TABSTOP);
	uFormat |= (DT_LEFT | DT_NOPREFIX);
	
	/* get the "default" font from the DC */
	SavedDC = SaveDC(hdc);
	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
	SelectObject(hdc, hfontBase);
	/* clear the other fonts, they are created "on demand" */
	for (Index = 0; Index < FV_NUMBER; Index++)
		hfontSpecial[Index] = NULL;
	hfontSpecial[0] = hfontBase;
	Styles = 0; /* assume the active font is normal weight, roman, 
non-underlined */
	
				/* get font height (use characters with ascender and descender);
				* we make the assumption here that changing the font style will
				* not change the font height
	*/
	GetTextExtentPoint32(hdc, _T("�y"), 2, &size);
	LineHeight = size.cy;
	
	/* run through the string, word for word */
	XPos = 0;
	MinWidth = 0;
	stacktop = 0;
	CurStyles = -1; /* force a select of the proper style */
	Height = 0;
	WhiteSpace = FALSE;
	
	Start = lpString;
	for ( ;; ) {
		Tag = GetToken(&Start, &nCount, &TokenLength, &WhiteSpace);
		if (Tag < 0)
			break;
		switch (Tag & ~ENDFLAG) {
		case tP:
			if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
				if (Start != lpString)
					Height += 3 * LineHeight / 2;
				XPos = 0;
			} /* if */
			break;
		case tBR:
			if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
				Height += LineHeight;
				XPos = 0;
			} /* if */
			break;
		case tB:
			Styles = (Tag & ENDFLAG) ? Styles & ~FV_BOLD : Styles | FV_BOLD;
			break;
		case tI:
			Styles = (Tag & ENDFLAG) ? Styles & ~FV_ITALIC : Styles | FV_ITALIC;
			break;
		case tU:
			Styles = (Tag & ENDFLAG) ? Styles & ~FV_UNDERLINE : Styles | 
FV_UNDERLINE;
			break;
		case tSUB:
			Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUBSCRIPT : Styles | 
FV_SUBSCRIPT;
			break;
		case tSUP:
			Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUPERSCRIPT : Styles | 
FV_SUPERSCRIPT;
			break;
		case tFONT:
			if ((Tag & ENDFLAG) == 0) {
				if (_tcsnicmp(Start + 6, _T("color="), 6) == 0)
					PushColor(hdc, ParseColor(Start + 12));
			} else {
				PopColor(hdc);
			} /* if */
			break;
		default:
			if (Tag == (tNONE | ENDFLAG))
				break;
			if (CurStyles != Styles) {
				if (hfontSpecial[Styles] == NULL)
					hfontSpecial[Styles] = GetFontVariant(hdc, hfontBase, Styles);
				CurStyles = Styles;
				SelectObject(hdc, hfontSpecial[Styles]);
				/* get the width of a space character (for word spacing) */
				GetTextExtentPoint32(hdc, _T(" "), 1, &size);
				WidthOfSPace = size.cx;
			} /* if */
			/* check word length, check whether to wrap around */
			GetTextExtentPoint32(hdc, Start, TokenLength, &size);
			if (size.cx > MaxWidth)
				MaxWidth = size.cx;   /* must increase width: long non-breakable word */
			if (WhiteSpace)
				XPos += WidthOfSPace;
			if (XPos + size.cx > MaxWidth && WhiteSpace) {
				if ((uFormat & DT_WORDBREAK) != 0) {
					/* word wrap */
					Height += LineHeight;
					XPos = 0;
				} else {
					/* no word wrap, must increase the width */
					MaxWidth = XPos + size.cx;
				} /* if */
			} /* if */
			/* output text (unless DT_CALCRECT is set) */
			if ((uFormat & DT_CALCRECT) == 0) {
				/* handle negative heights, too (suggestion of "Sims")  */
				/*if (Top < 0)
				{
					SetRect(&rc, Left + XPos, Top - Height,
					Left + MaxWidth, Top - (Height + LineHeight));
				}
				else*/
				{
					SetRect(&rc, Left + XPos, Top + Height,
					Left + MaxWidth, Top + Height + LineHeight);
				}
				
				/* reposition subscript text to align below the baseline */
				DrawText(hdc, Start, TokenLength, &rc,
					uFormat | ((Styles & FV_SUBSCRIPT) ? DT_BOTTOM | DT_SINGLELINE : 0));
				
					/* for the underline style, the spaces between words should be
					* underlined as well
				*/
				if (WhiteSpace && (Styles & FV_UNDERLINE) && XPos >= WidthOfSPace)
				{
					if (Top < 0)
					{
						SetRect(&rc, Left + XPos - WidthOfSPace, Top - Height,
							Left + XPos, Top - (Height + LineHeight));
					}
					else
					{
						SetRect(&rc, Left + XPos - WidthOfSPace, Top + Height,
							Left + XPos, Top + Height + LineHeight);
					}
					DrawText(hdc, _T(" "), 1, &rc, uFormat);
				} /* if */
			} /* if */
			/* update current position */
			XPos += size.cx;
			if (XPos > MinWidth)
				MinWidth = XPos;
			WhiteSpace = FALSE;
     } /* if */
	
     Start += TokenLength;
   } /* for */

   RestoreDC(hdc, SavedDC);
   for (Index = 1; Index < FV_NUMBER; Index++) /* do not erase 
hfontSpecial[0] */
	  if (hfontSpecial[Index] != NULL)
		  DeleteObject(hfontSpecial[Index]);
	
	  /* store width and height back into the lpRect structure */
	  if ((uFormat & DT_CALCRECT) != 0 && lpRect!=NULL) {
		  lpRect->right = lpRect->left + MinWidth;
		  if (lpRect->top < 0)
			  lpRect->bottom = lpRect->top - (Height + LineHeight);
		  else
			  lpRect->bottom = lpRect->top + Height + LineHeight;
	  } /* if */
	
	  return Height;
}




Joseph M. Newcomer a �crit :
> On Mon, 20 Aug 2007 15:05:43 +0200, mosfet <john.doe@anonymous.org> wrote:
> 
>> Hi,
>>
>> I would like to modify a function used to render some HTML and use the 
>> font I have choosen :
>>
>>
>> // C functions
>> int __stdcall DrawHTML(
>>                        HDC     hdc,        // handle of device context
>>                        LPCTSTR lpString,   // address of string to draw
>>                        int     nCount,     // string length, in characters
>>                        LPRECT  lpRect,     // address of structure with 
>> formatting dimensions
>>                        UINT    uFormat     // text-drawing flags
>> 					   )
>> {
>> ...
>>
>>
>> /* get the "default" font from the DC */
>> 	SavedDC = SaveDC(hdc);
> ****
> You do a SaveDC but not a RestoreDC?  
> ****
>> 	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>> 	SelectObject(hdc, hfontBase);
> ****
> It would be easier to write
> 	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
> and not worry about the SelectObject pair
> ****
>> 	/* clear the other fonts, they are created "on demand" */
>> 	for (Index = 0; Index < FV_NUMBER; Index++)
>> 		hfontSpecial[Index] = NULL;
>> 	hfontSpecial[0] = hfontBase;
> ****
> Note that if, in between times, the font which is currently selected into the DC is
> deleted, the old handle you have saved here will become meaningless.  Therefore, you
> cannot rely on the fact that this handle will still be valid at the time you use it.
> Better to do an array of LOGFONT values, rather than an array of HFONTs.
> ****
>> ...
>> }
>>
>>
>> Here is my code :
>>
>>
>> void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
>> BOOL bSelected)
>> {
>>
>>  CFont* pOldFont  = MemDC.SelectObject( &m_font );
>>
>> DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
>> 			&rc,DT_LEFT|DT_WORDBREAK);
> ****
> So why do you save the font in the MemDC when you don't actually use it?  Note that the
> m_font handle must represent a valid font to be selected, but the line seems to have no
> meaning as shown in this function.  I would also suggest something like
> 	HDC dc = pDC->GetSafeHdc();
> 	if(dc == NULL)
> 	    return;
>                DrawHTML(dc, ...as above...);
>> }
>>
>>
>>
>> My problem is I don't know how to modify DrawHTML to take the font 
>> specified in DrawItem because from what I understand DrawHTML is using a 
>> default font :
>>
>> hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>> 	SelectObject(hdc, hfontBase);
>>
> ****
> I don't see the relationship of the above code to the problem.  Where is this line of
> code?  I also could not find any method called DrawHTML in the MSDN documentation, could
> you say more about where it is implemented or what it is supposed to do?
> 					joe
> ****
>>
>>
>>
>>
>>
>>
>>
>>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
0
8/20/2007 1:37:16 PM
Finally I did this :

hfontBase = (HFONT)::GetCurrentObject(hdc, OBJ_FONT);
if (hfontBase == NULL){
	hfontBase = (HFONT) GetStockObject(SYSTEM_FONT) );
}
SelectObject(hdc, hfontBase);


mosfet a �crit :
> Actually I want to use the following control 
> http://www.codeproject.com/listctrl/html_listctrl.asp (on Smartphone but 
> that's not the question) that is a Custom CListCtrl deriving from CWnd.
> It's appropriate because on smartphone you don't have much space and 
> this listctrl allow to have a different size for each row in addtion to 
> support a few HTML tags.
> 
> But when reading the code I saw that it uses hfontBase = 
> (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT)); and I 
> think it would be better to use the font selected in the control.
> For instanc I could do a SetFont on my listctrl and the DrawHTML 
> function should use it to do its rendering (bold, italic, ...)
> 
> 
> 
> About savedc and restordc it's because I haven't posted all the code.
> 
> int __stdcall DrawHTML(
>                        HDC     hdc,        // handle of device context
>                        LPCTSTR lpString,   // address of string to draw
>                        int     nCount,     // string length, in characters
>                        LPRECT  lpRect,     // address of structure with 
> formatting dimensions
>                        UINT    uFormat     // text-drawing flags
>                        )
> {
>     LPCTSTR Start;
>     int Left, Top, MaxWidth, MinWidth, Height;
>     int SavedDC;
>     int Tag, TokenLength;
>     HFONT hfontBase, hfontSpecial[FV_NUMBER];
>     int Styles, CurStyles;
>     SIZE size;
>     int Index, LineHeight;
>     POINT CurPos;
>     int WidthOfSPace, XPos;
>     BOOL WhiteSpace;
>     RECT rc;
>     
>     if (hdc == NULL || lpString == NULL)
>         return 0;
>     if (nCount < 0)
>         nCount = _tcslen(lpString);
>     
>     if (lpRect != NULL) {
>         Left = lpRect->left;
>         Top = lpRect->top;
>         MaxWidth = lpRect->right - lpRect->left;
>     } else {
>         GetCurrentPositionEx(hdc, &CurPos);
>         Left = CurPos.x;
>         Top = CurPos.y;
>         MaxWidth = GetDeviceCaps(hdc, HORZRES) - Left;
>     } /* if */
>     if (MaxWidth < 0)
>         MaxWidth = 0;
>     
>     /* toggle flags we do not support */
>     uFormat &= ~(DT_CENTER | DT_RIGHT | DT_TABSTOP);
>     uFormat |= (DT_LEFT | DT_NOPREFIX);
>     
>     /* get the "default" font from the DC */
>     SavedDC = SaveDC(hdc);
>     hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
>     hfontBase = (HFONT)SelectObject(hdc, 
> (HFONT)GetStockObject(SYSTEM_FONT));
>     SelectObject(hdc, hfontBase);
>     /* clear the other fonts, they are created "on demand" */
>     for (Index = 0; Index < FV_NUMBER; Index++)
>         hfontSpecial[Index] = NULL;
>     hfontSpecial[0] = hfontBase;
>     Styles = 0; /* assume the active font is normal weight, roman, 
> non-underlined */
>     
>                 /* get font height (use characters with ascender and 
> descender);
>                 * we make the assumption here that changing the font 
> style will
>                 * not change the font height
>     */
>     GetTextExtentPoint32(hdc, _T("�y"), 2, &size);
>     LineHeight = size.cy;
>     
>     /* run through the string, word for word */
>     XPos = 0;
>     MinWidth = 0;
>     stacktop = 0;
>     CurStyles = -1; /* force a select of the proper style */
>     Height = 0;
>     WhiteSpace = FALSE;
>     
>     Start = lpString;
>     for ( ;; ) {
>         Tag = GetToken(&Start, &nCount, &TokenLength, &WhiteSpace);
>         if (Tag < 0)
>             break;
>         switch (Tag & ~ENDFLAG) {
>         case tP:
>             if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
>                 if (Start != lpString)
>                     Height += 3 * LineHeight / 2;
>                 XPos = 0;
>             } /* if */
>             break;
>         case tBR:
>             if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
>                 Height += LineHeight;
>                 XPos = 0;
>             } /* if */
>             break;
>         case tB:
>             Styles = (Tag & ENDFLAG) ? Styles & ~FV_BOLD : Styles | 
> FV_BOLD;
>             break;
>         case tI:
>             Styles = (Tag & ENDFLAG) ? Styles & ~FV_ITALIC : Styles | 
> FV_ITALIC;
>             break;
>         case tU:
>             Styles = (Tag & ENDFLAG) ? Styles & ~FV_UNDERLINE : Styles | 
> FV_UNDERLINE;
>             break;
>         case tSUB:
>             Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUBSCRIPT : Styles | 
> FV_SUBSCRIPT;
>             break;
>         case tSUP:
>             Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUPERSCRIPT : Styles 
> | FV_SUPERSCRIPT;
>             break;
>         case tFONT:
>             if ((Tag & ENDFLAG) == 0) {
>                 if (_tcsnicmp(Start + 6, _T("color="), 6) == 0)
>                     PushColor(hdc, ParseColor(Start + 12));
>             } else {
>                 PopColor(hdc);
>             } /* if */
>             break;
>         default:
>             if (Tag == (tNONE | ENDFLAG))
>                 break;
>             if (CurStyles != Styles) {
>                 if (hfontSpecial[Styles] == NULL)
>                     hfontSpecial[Styles] = GetFontVariant(hdc, 
> hfontBase, Styles);
>                 CurStyles = Styles;
>                 SelectObject(hdc, hfontSpecial[Styles]);
>                 /* get the width of a space character (for word spacing) */
>                 GetTextExtentPoint32(hdc, _T(" "), 1, &size);
>                 WidthOfSPace = size.cx;
>             } /* if */
>             /* check word length, check whether to wrap around */
>             GetTextExtentPoint32(hdc, Start, TokenLength, &size);
>             if (size.cx > MaxWidth)
>                 MaxWidth = size.cx;   /* must increase width: long 
> non-breakable word */
>             if (WhiteSpace)
>                 XPos += WidthOfSPace;
>             if (XPos + size.cx > MaxWidth && WhiteSpace) {
>                 if ((uFormat & DT_WORDBREAK) != 0) {
>                     /* word wrap */
>                     Height += LineHeight;
>                     XPos = 0;
>                 } else {
>                     /* no word wrap, must increase the width */
>                     MaxWidth = XPos + size.cx;
>                 } /* if */
>             } /* if */
>             /* output text (unless DT_CALCRECT is set) */
>             if ((uFormat & DT_CALCRECT) == 0) {
>                 /* handle negative heights, too (suggestion of "Sims")  */
>                 /*if (Top < 0)
>                 {
>                     SetRect(&rc, Left + XPos, Top - Height,
>                     Left + MaxWidth, Top - (Height + LineHeight));
>                 }
>                 else*/
>                 {
>                     SetRect(&rc, Left + XPos, Top + Height,
>                     Left + MaxWidth, Top + Height + LineHeight);
>                 }
>                
>                 /* reposition subscript text to align below the baseline */
>                 DrawText(hdc, Start, TokenLength, &rc,
>                     uFormat | ((Styles & FV_SUBSCRIPT) ? DT_BOTTOM | 
> DT_SINGLELINE : 0));
>                
>                     /* for the underline style, the spaces between words 
> should be
>                     * underlined as well
>                 */
>                 if (WhiteSpace && (Styles & FV_UNDERLINE) && XPos >= 
> WidthOfSPace)
>                 {
>                     if (Top < 0)
>                     {
>                         SetRect(&rc, Left + XPos - WidthOfSPace, Top - 
> Height,
>                             Left + XPos, Top - (Height + LineHeight));
>                     }
>                     else
>                     {
>                         SetRect(&rc, Left + XPos - WidthOfSPace, Top + 
> Height,
>                             Left + XPos, Top + Height + LineHeight);
>                     }
>                     DrawText(hdc, _T(" "), 1, &rc, uFormat);
>                 } /* if */
>             } /* if */
>             /* update current position */
>             XPos += size.cx;
>             if (XPos > MinWidth)
>                 MinWidth = XPos;
>             WhiteSpace = FALSE;
>     } /* if */
>     
>     Start += TokenLength;
>   } /* for */
> 
>   RestoreDC(hdc, SavedDC);
>   for (Index = 1; Index < FV_NUMBER; Index++) /* do not erase 
> hfontSpecial[0] */
>       if (hfontSpecial[Index] != NULL)
>           DeleteObject(hfontSpecial[Index]);
>     
>       /* store width and height back into the lpRect structure */
>       if ((uFormat & DT_CALCRECT) != 0 && lpRect!=NULL) {
>           lpRect->right = lpRect->left + MinWidth;
>           if (lpRect->top < 0)
>               lpRect->bottom = lpRect->top - (Height + LineHeight);
>           else
>               lpRect->bottom = lpRect->top + Height + LineHeight;
>       } /* if */
>     
>       return Height;
> }
> 
> 
> 
> 
> Joseph M. Newcomer a �crit :
>> On Mon, 20 Aug 2007 15:05:43 +0200, mosfet <john.doe@anonymous.org> 
>> wrote:
>>
>>> Hi,
>>>
>>> I would like to modify a function used to render some HTML and use 
>>> the font I have choosen :
>>>
>>>
>>> // C functions
>>> int __stdcall DrawHTML(
>>>                        HDC     hdc,        // handle of device context
>>>                        LPCTSTR lpString,   // address of string to draw
>>>                        int     nCount,     // string length, in 
>>> characters
>>>                        LPRECT  lpRect,     // address of structure 
>>> with formatting dimensions
>>>                        UINT    uFormat     // text-drawing flags
>>>                        )
>>> {
>>> ...
>>>
>>>
>>> /* get the "default" font from the DC */
>>>     SavedDC = SaveDC(hdc);
>> ****
>> You do a SaveDC but not a RestoreDC?  ****
>>>     hfontBase = (HFONT)SelectObject(hdc, 
>>> (HFONT)GetStockObject(SYSTEM_FONT));
>>>     SelectObject(hdc, hfontBase);
>> ****
>> It would be easier to write
>>     hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
>> and not worry about the SelectObject pair
>> ****
>>>     /* clear the other fonts, they are created "on demand" */
>>>     for (Index = 0; Index < FV_NUMBER; Index++)
>>>         hfontSpecial[Index] = NULL;
>>>     hfontSpecial[0] = hfontBase;
>> ****
>> Note that if, in between times, the font which is currently selected 
>> into the DC is
>> deleted, the old handle you have saved here will become meaningless.  
>> Therefore, you
>> cannot rely on the fact that this handle will still be valid at the 
>> time you use it.
>> Better to do an array of LOGFONT values, rather than an array of HFONTs.
>> ****
>>> ...
>>> }
>>>
>>>
>>> Here is my code :
>>>
>>>
>>> void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM 
>>> *pItem, BOOL bSelected)
>>> {
>>>
>>>  CFont* pOldFont  = MemDC.SelectObject( &m_font );
>>>
>>> DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(), 
>>>
>>>             &rc,DT_LEFT|DT_WORDBREAK);
>> ****
>> So why do you save the font in the MemDC when you don't actually use 
>> it?  Note that the
>> m_font handle must represent a valid font to be selected, but the line 
>> seems to have no
>> meaning as shown in this function.  I would also suggest something like
>>     HDC dc = pDC->GetSafeHdc();
>>     if(dc == NULL)
>>         return;
>>                DrawHTML(dc, ...as above...);
>>> }
>>>
>>>
>>>
>>> My problem is I don't know how to modify DrawHTML to take the font 
>>> specified in DrawItem because from what I understand DrawHTML is 
>>> using a default font :
>>>
>>> hfontBase = (HFONT)SelectObject(hdc, 
>>> (HFONT)GetStockObject(SYSTEM_FONT));
>>>     SelectObject(hdc, hfontBase);
>>>
>> ****
>> I don't see the relationship of the above code to the problem.  Where 
>> is this line of
>> code?  I also could not find any method called DrawHTML in the MSDN 
>> documentation, could
>> you say more about where it is implemented or what it is supposed to do?
>>                     joe
>> ****
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
0
8/20/2007 1:41:06 PM
See below,,,
On Mon, 20 Aug 2007 15:37:16 +0200, mosfet <john.doe@anonymous.org> wrote:

>Actually I want to use the following control 
>http://www.codeproject.com/listctrl/html_listctrl.asp (on Smartphone but 
>that's not the question) that is a Custom CListCtrl deriving from CWnd.
>It's appropriate because on smartphone you don't have much space and 
>this listctrl allow to have a different size for each row in addtion to 
>support a few HTML tags.
>
>But when reading the code I saw that it uses hfontBase = 
>(HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT)); and I 
>think it would be better to use the font selected in the control.
>For instanc I could do a SetFont on my listctrl and the DrawHTML 
>function should use it to do its rendering (bold, italic, ...)
>
>
>
>About savedc and restordc it's because I haven't posted all the code.
>
>int __stdcall DrawHTML(
>                        HDC     hdc,        // handle of device context
>                        LPCTSTR lpString,   // address of string to draw
>                        int     nCount,     // string length, in characters
>                        LPRECT  lpRect,     // address of structure with 
>formatting dimensions
>                        UINT    uFormat     // text-drawing flags
>					   )
>{
>	LPCTSTR Start;
>	int Left, Top, MaxWidth, MinWidth, Height;
****
You should avoid commas in declaration lists.  It makes the code unreadable, and hard to
edit.  One variable, one line should be the rule.
****
>	int SavedDC;
>	int Tag, TokenLength;
>	HFONT hfontBase, hfontSpecial[FV_NUMBER];
>	int Styles, CurStyles;
>	SIZE size;
>	int Index, LineHeight;
>	POINT CurPos;
>	int WidthOfSPace, XPos;
>	BOOL WhiteSpace;
>	RECT rc;
>	
>	if (hdc == NULL || lpString == NULL)
>		return 0;
>	if (nCount < 0)
>		nCount = _tcslen(lpString);
>	
>	if (lpRect != NULL) {
>		Left = lpRect->left;
>		Top = lpRect->top;
>		MaxWidth = lpRect->right - lpRect->left;
>	} else {
>		GetCurrentPositionEx(hdc, &CurPos);
>		Left = CurPos.x;
>		Top = CurPos.y;
>		MaxWidth = GetDeviceCaps(hdc, HORZRES) - Left;
****
Note that this is very sensitive to where the current position is; can you really trust it
to be in a sensible place?
****
>	} /* if */
****
It is good to indicate the end of nested structures, but this tends to break down if you
have a nested if.  I tend to something stronger:
	if(lpRect != NULL)
	    { /* Use given rect */
	     ... code here
	    } /* Use given rect */
	else
	   { /* Compute default rect */
	    ... code here
	   } /* Compute default rect */

This deals with one of our weaknesses as human beings: we cannot cope well with nesting.
My editor, when I type {, puts in a comment and leaves me in the middle ready to type the
contents; when I type }, my editor grabs the comment from the matching { and duplicates
it, meaning I never, ever have to guess which } matches which {.  
****
>	if (MaxWidth < 0)
>		MaxWidth = 0;
>	
>	/* toggle flags we do not support */
****
Actually, you are not "toggling" them (which would imply setting them to the opposite of
their current value), you are "clearing" them.  And the next line "sets" others.
****
>	uFormat &= ~(DT_CENTER | DT_RIGHT | DT_TABSTOP);
>	uFormat |= (DT_LEFT | DT_NOPREFIX);
>	
>	/* get the "default" font from the DC */
>	SavedDC = SaveDC(hdc);
>	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
>	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>	SelectObject(hdc, hfontBase);
***
But the above two lines with SelectObject is now meaningless!
Get rid of these two lines, since GetCurrentObject does what you need! 
****
>	/* clear the other fonts, they are created "on demand" */
>	for (Index = 0; Index < FV_NUMBER; Index++)
>		hfontSpecial[Index] = NULL;
****
What if they weren't already NULL?  If they already existed, you now have a handle leak.
They should be cleared when the fonts are deleted using ::DeleteObject, not here.
****
>	hfontSpecial[0] = hfontBase;
>	Styles = 0; /* assume the active font is normal weight, roman, 
>non-underlined */
>	
>				/* get font height (use characters with ascender and descender);
>				* we make the assumption here that changing the font style will
>				* not change the font height
>	*/
>	GetTextExtentPoint32(hdc, _T("�y"), 2, &size);
>	LineHeight = size.cy;
****
GetTextMetrics would be a better choice here, since you can't really depend on how the
font represents �.  You would then use the tmHeight for line height, although you usually
get a better result from using tmHeight + tmInternalLeading.  These will account for all
the ascender/descender values, not just the incidental representations of two characters
(which may not have ascenders and descenders in a particular font)
****
>	
>	/* run through the string, word for word */
***
This code is a bit dangerous, because you really don't know what a "word" is (there is a
myth that words are separated by whitespace, which is only true in a limited number of
languages)
>	XPos = 0;
>	MinWidth = 0;
>	stacktop = 0;
>	CurStyles = -1; /* force a select of the proper style */
>	Height = 0;
>	WhiteSpace = FALSE;
>	
>	Start = lpString;
>	for ( ;; ) {
>		Tag = GetToken(&Start, &nCount, &TokenLength, &WhiteSpace);
>		if (Tag < 0)
>			break;
>		switch (Tag & ~ENDFLAG) {
>		case tP:
****
Putting comments like <p> would make it a little easier to understand what is going on
here...
****
>			if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
>				if (Start != lpString)
>					Height += 3 * LineHeight / 2;
>				XPos = 0;
>			} /* if */
>			break;
>		case tBR:
>			if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
>				Height += LineHeight;
>				XPos = 0;
>			} /* if */
>			break;
>		case tB:
>			Styles = (Tag & ENDFLAG) ? Styles & ~FV_BOLD : Styles | FV_BOLD;
>			break;
>		case tI:
>			Styles = (Tag & ENDFLAG) ? Styles & ~FV_ITALIC : Styles | FV_ITALIC;
>			break;
>		case tU:
>			Styles = (Tag & ENDFLAG) ? Styles & ~FV_UNDERLINE : Styles | 
>FV_UNDERLINE;
>			break;
>		case tSUB:
>			Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUBSCRIPT : Styles | 
>FV_SUBSCRIPT;
>			break;
>		case tSUP:
>			Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUPERSCRIPT : Styles | 
>FV_SUPERSCRIPT;
>			break;
>		case tFONT:
>			if ((Tag & ENDFLAG) == 0) {
>				if (_tcsnicmp(Start + 6, _T("color="), 6) == 0)
>					PushColor(hdc, ParseColor(Start + 12));
****
This really makes a very strong assumption which is almost certainly not true, that the
specification is always 
	<font color="colorid">
but it could just as easily be 
	<font size="3" color="colorid">
so you really have to parse the parameters as an unordered set.
****
>			} else {
>				PopColor(hdc);
****
Actually, you need to pop the entire font context, not just the color, because a font
specification could change the size as well.
****
>			} /* if */
>			break;
>		default:
****
What about &-escapes such as &lt;?
****
>			if (Tag == (tNONE | ENDFLAG))
>				break;
>			if (CurStyles != Styles) {
>				if (hfontSpecial[Styles] == NULL)
>					hfontSpecial[Styles] = GetFontVariant(hdc, hfontBase, Styles);
>				CurStyles = Styles;
>				SelectObject(hdc, hfontSpecial[Styles]);
>				/* get the width of a space character (for word spacing) */
>				GetTextExtentPoint32(hdc, _T(" "), 1, &size);
>				WidthOfSPace = size.cx;
>			} /* if */
>			/* check word length, check whether to wrap around */
>			GetTextExtentPoint32(hdc, Start, TokenLength, &size);
****
As I learned to my dismay, this isn't really reliable for languages other than English. It
doesn't work with certain accented characters even in English. This gets you into issues
such as proper handling of Unicode.  You would be better off using DrawText, which should
do the correct font computations correctly.  Generally, trying to do layout on your own is
very risky.  Perhaps Mihai can jump in here; he's one of the Unicode layout experts.  I
got into serious trouble trying to do word breaks in a client app, mostly because the
client gave me a set of "critical" specs that were incompatible with the reality of
international fonts, and it took a massive amount of effort to get them to change the
specs to recognize the fact that their specs wouldn't work.
**** 
>			if (size.cx > MaxWidth)
>				MaxWidth = size.cx;   /* must increase width: long non-breakable word */
>			if (WhiteSpace)
>				XPos += WidthOfSPace;
>			if (XPos + size.cx > MaxWidth && WhiteSpace) {
>				if ((uFormat & DT_WORDBREAK) != 0) {
>					/* word wrap */
>					Height += LineHeight;
>					XPos = 0;
>				} else {
>					/* no word wrap, must increase the width */
>					MaxWidth = XPos + size.cx;
>				} /* if */
>			} /* if */
>			/* output text (unless DT_CALCRECT is set) */
>			if ((uFormat & DT_CALCRECT) == 0) {
>				/* handle negative heights, too (suggestion of "Sims")  */
>				/*if (Top < 0)
>				{
>					SetRect(&rc, Left + XPos, Top - Height,
>					Left + MaxWidth, Top - (Height + LineHeight));
>				}
>				else*/
>				{
>					SetRect(&rc, Left + XPos, Top + Height,
>					Left + MaxWidth, Top + Height + LineHeight);
>				}
>				
>				/* reposition subscript text to align below the baseline */
>				DrawText(hdc, Start, TokenLength, &rc,
>					uFormat | ((Styles & FV_SUBSCRIPT) ? DT_BOTTOM | DT_SINGLELINE : 0));
>				
>					/* for the underline style, the spaces between words should be
>					* underlined as well
>				*/
>				if (WhiteSpace && (Styles & FV_UNDERLINE) && XPos >= WidthOfSPace)
>				{
>					if (Top < 0)
>					{
>						SetRect(&rc, Left + XPos - WidthOfSPace, Top - Height,
>							Left + XPos, Top - (Height + LineHeight));
>					}
>					else
>					{
>						SetRect(&rc, Left + XPos - WidthOfSPace, Top + Height,
>							Left + XPos, Top + Height + LineHeight);
>					}
>					DrawText(hdc, _T(" "), 1, &rc, uFormat);
>				} /* if */
>			} /* if */
>			/* update current position */
>			XPos += size.cx;
>			if (XPos > MinWidth)
>				MinWidth = XPos;
>			WhiteSpace = FALSE;
>     } /* if */
>	
>     Start += TokenLength;
>   } /* for */
>
>   RestoreDC(hdc, SavedDC);
>   for (Index = 1; Index < FV_NUMBER; Index++) /* do not erase 
>hfontSpecial[0] */
>	  if (hfontSpecial[Index] != NULL)
>		  DeleteObject(hfontSpecial[Index]);
***
This is where you should set the handles to NULL.  Not at the beginning.

Overall, there are a huge number of potential problems here as soon as you move outside
English, and the issue of height and word break needs to be treated in a more
culturally-neutral fashion.
***
>	
>	  /* store width and height back into the lpRect structure */
>	  if ((uFormat & DT_CALCRECT) != 0 && lpRect!=NULL) {
>		  lpRect->right = lpRect->left + MinWidth;
>		  if (lpRect->top < 0)
>			  lpRect->bottom = lpRect->top - (Height + LineHeight);
>		  else
>			  lpRect->bottom = lpRect->top + Height + LineHeight;
>	  } /* if */
>	
>	  return Height;
>}
>
>
>
>
>Joseph M. Newcomer a �crit :
>> On Mon, 20 Aug 2007 15:05:43 +0200, mosfet <john.doe@anonymous.org> wrote:
>> 
>>> Hi,
>>>
>>> I would like to modify a function used to render some HTML and use the 
>>> font I have choosen :
>>>
>>>
>>> // C functions
>>> int __stdcall DrawHTML(
>>>                        HDC     hdc,        // handle of device context
>>>                        LPCTSTR lpString,   // address of string to draw
>>>                        int     nCount,     // string length, in characters
>>>                        LPRECT  lpRect,     // address of structure with 
>>> formatting dimensions
>>>                        UINT    uFormat     // text-drawing flags
>>> 					   )
>>> {
>>> ...
>>>
>>>
>>> /* get the "default" font from the DC */
>>> 	SavedDC = SaveDC(hdc);
>> ****
>> You do a SaveDC but not a RestoreDC?  
>> ****
>>> 	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>>> 	SelectObject(hdc, hfontBase);
>> ****
>> It would be easier to write
>> 	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
>> and not worry about the SelectObject pair
>> ****
>>> 	/* clear the other fonts, they are created "on demand" */
>>> 	for (Index = 0; Index < FV_NUMBER; Index++)
>>> 		hfontSpecial[Index] = NULL;
>>> 	hfontSpecial[0] = hfontBase;
>> ****
>> Note that if, in between times, the font which is currently selected into the DC is
>> deleted, the old handle you have saved here will become meaningless.  Therefore, you
>> cannot rely on the fact that this handle will still be valid at the time you use it.
>> Better to do an array of LOGFONT values, rather than an array of HFONTs.
>> ****
>>> ...
>>> }
>>>
>>>
>>> Here is my code :
>>>
>>>
>>> void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
>>> BOOL bSelected)
>>> {
>>>
>>>  CFont* pOldFont  = MemDC.SelectObject( &m_font );
>>>
>>> DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
>>> 			&rc,DT_LEFT|DT_WORDBREAK);
>> ****
>> So why do you save the font in the MemDC when you don't actually use it?  Note that the
>> m_font handle must represent a valid font to be selected, but the line seems to have no
>> meaning as shown in this function.  I would also suggest something like
>> 	HDC dc = pDC->GetSafeHdc();
>> 	if(dc == NULL)
>> 	    return;
>>                DrawHTML(dc, ...as above...);
>>> }
>>>
>>>
>>>
>>> My problem is I don't know how to modify DrawHTML to take the font 
>>> specified in DrawItem because from what I understand DrawHTML is using a 
>>> default font :
>>>
>>> hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>>> 	SelectObject(hdc, hfontBase);
>>>
>> ****
>> I don't see the relationship of the above code to the problem.  Where is this line of
>> code?  I also could not find any method called DrawHTML in the MSDN documentation, could
>> you say more about where it is implemented or what it is supposed to do?
>> 					joe
>> ****
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
8/20/2007 2:27:37 PM
Thanks for all this positive remarks but for some of them it may be true 
but not as important as it seems.
For instance about the word break, languages that don't use space as 
separator don't interest me ;-)
if you know a tiny, free, well written HTML engine(engine is not really 
appropriate because I only needs bold italic, font color and size) just 
let me know ...
I am not interested by CHtmlView or this kind of solution because it 
takes too much space for what I need.



Joseph M. Newcomer a �crit :
> See below,,,
> On Mon, 20 Aug 2007 15:37:16 +0200, mosfet <john.doe@anonymous.org> wrote:
> 
>> Actually I want to use the following control 
>> http://www.codeproject.com/listctrl/html_listctrl.asp (on Smartphone but 
>> that's not the question) that is a Custom CListCtrl deriving from CWnd.
>> It's appropriate because on smartphone you don't have much space and 
>> this listctrl allow to have a different size for each row in addtion to 
>> support a few HTML tags.
>>
>> But when reading the code I saw that it uses hfontBase = 
>> (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT)); and I 
>> think it would be better to use the font selected in the control.
>> For instanc I could do a SetFont on my listctrl and the DrawHTML 
>> function should use it to do its rendering (bold, italic, ...)
>>
>>
>>
>> About savedc and restordc it's because I haven't posted all the code.
>>
>> int __stdcall DrawHTML(
>>                        HDC     hdc,        // handle of device context
>>                        LPCTSTR lpString,   // address of string to draw
>>                        int     nCount,     // string length, in characters
>>                        LPRECT  lpRect,     // address of structure with 
>> formatting dimensions
>>                        UINT    uFormat     // text-drawing flags
>> 					   )
>> {
>> 	LPCTSTR Start;
>> 	int Left, Top, MaxWidth, MinWidth, Height;
> ****
> You should avoid commas in declaration lists.  It makes the code unreadable, and hard to
> edit.  One variable, one line should be the rule.
> ****
>> 	int SavedDC;
>> 	int Tag, TokenLength;
>> 	HFONT hfontBase, hfontSpecial[FV_NUMBER];
>> 	int Styles, CurStyles;
>> 	SIZE size;
>> 	int Index, LineHeight;
>> 	POINT CurPos;
>> 	int WidthOfSPace, XPos;
>> 	BOOL WhiteSpace;
>> 	RECT rc;
>> 	
>> 	if (hdc == NULL || lpString == NULL)
>> 		return 0;
>> 	if (nCount < 0)
>> 		nCount = _tcslen(lpString);
>> 	
>> 	if (lpRect != NULL) {
>> 		Left = lpRect->left;
>> 		Top = lpRect->top;
>> 		MaxWidth = lpRect->right - lpRect->left;
>> 	} else {
>> 		GetCurrentPositionEx(hdc, &CurPos);
>> 		Left = CurPos.x;
>> 		Top = CurPos.y;
>> 		MaxWidth = GetDeviceCaps(hdc, HORZRES) - Left;
> ****
> Note that this is very sensitive to where the current position is; can you really trust it
> to be in a sensible place?
> ****
>> 	} /* if */
> ****
> It is good to indicate the end of nested structures, but this tends to break down if you
> have a nested if.  I tend to something stronger:
> 	if(lpRect != NULL)
> 	    { /* Use given rect */
> 	     ... code here
> 	    } /* Use given rect */
> 	else
> 	   { /* Compute default rect */
> 	    ... code here
> 	   } /* Compute default rect */
> 
> This deals with one of our weaknesses as human beings: we cannot cope well with nesting.
> My editor, when I type {, puts in a comment and leaves me in the middle ready to type the
> contents; when I type }, my editor grabs the comment from the matching { and duplicates
> it, meaning I never, ever have to guess which } matches which {.  
> ****
>> 	if (MaxWidth < 0)
>> 		MaxWidth = 0;
>> 	
>> 	/* toggle flags we do not support */
> ****
> Actually, you are not "toggling" them (which would imply setting them to the opposite of
> their current value), you are "clearing" them.  And the next line "sets" others.
> ****
>> 	uFormat &= ~(DT_CENTER | DT_RIGHT | DT_TABSTOP);
>> 	uFormat |= (DT_LEFT | DT_NOPREFIX);
>> 	
>> 	/* get the "default" font from the DC */
>> 	SavedDC = SaveDC(hdc);
>> 	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
>> 	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>> 	SelectObject(hdc, hfontBase);
> ***
> But the above two lines with SelectObject is now meaningless!
> Get rid of these two lines, since GetCurrentObject does what you need! 
> ****
>> 	/* clear the other fonts, they are created "on demand" */
>> 	for (Index = 0; Index < FV_NUMBER; Index++)
>> 		hfontSpecial[Index] = NULL;
> ****
> What if they weren't already NULL?  If they already existed, you now have a handle leak.
> They should be cleared when the fonts are deleted using ::DeleteObject, not here.
> ****
>> 	hfontSpecial[0] = hfontBase;
>> 	Styles = 0; /* assume the active font is normal weight, roman, 
>> non-underlined */
>> 	
>> 				/* get font height (use characters with ascender and descender);
>> 				* we make the assumption here that changing the font style will
>> 				* not change the font height
>> 	*/
>> 	GetTextExtentPoint32(hdc, _T("�y"), 2, &size);
>> 	LineHeight = size.cy;
> ****
> GetTextMetrics would be a better choice here, since you can't really depend on how the
> font represents �.  You would then use the tmHeight for line height, although you usually
> get a better result from using tmHeight + tmInternalLeading.  These will account for all
> the ascender/descender values, not just the incidental representations of two characters
> (which may not have ascenders and descenders in a particular font)
> ****
>> 	
>> 	/* run through the string, word for word */
> ***
> This code is a bit dangerous, because you really don't know what a "word" is (there is a
> myth that words are separated by whitespace, which is only true in a limited number of
> languages)
>> 	XPos = 0;
>> 	MinWidth = 0;
>> 	stacktop = 0;
>> 	CurStyles = -1; /* force a select of the proper style */
>> 	Height = 0;
>> 	WhiteSpace = FALSE;
>> 	
>> 	Start = lpString;
>> 	for ( ;; ) {
>> 		Tag = GetToken(&Start, &nCount, &TokenLength, &WhiteSpace);
>> 		if (Tag < 0)
>> 			break;
>> 		switch (Tag & ~ENDFLAG) {
>> 		case tP:
> ****
> Putting comments like <p> would make it a little easier to understand what is going on
> here...
> ****
>> 			if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
>> 				if (Start != lpString)
>> 					Height += 3 * LineHeight / 2;
>> 				XPos = 0;
>> 			} /* if */
>> 			break;
>> 		case tBR:
>> 			if ((Tag & ENDFLAG) == 0 && (uFormat & DT_SINGLELINE) == 0) {
>> 				Height += LineHeight;
>> 				XPos = 0;
>> 			} /* if */
>> 			break;
>> 		case tB:
>> 			Styles = (Tag & ENDFLAG) ? Styles & ~FV_BOLD : Styles | FV_BOLD;
>> 			break;
>> 		case tI:
>> 			Styles = (Tag & ENDFLAG) ? Styles & ~FV_ITALIC : Styles | FV_ITALIC;
>> 			break;
>> 		case tU:
>> 			Styles = (Tag & ENDFLAG) ? Styles & ~FV_UNDERLINE : Styles | 
>> FV_UNDERLINE;
>> 			break;
>> 		case tSUB:
>> 			Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUBSCRIPT : Styles | 
>> FV_SUBSCRIPT;
>> 			break;
>> 		case tSUP:
>> 			Styles = (Tag & ENDFLAG) ? Styles & ~FV_SUPERSCRIPT : Styles | 
>> FV_SUPERSCRIPT;
>> 			break;
>> 		case tFONT:
>> 			if ((Tag & ENDFLAG) == 0) {
>> 				if (_tcsnicmp(Start + 6, _T("color="), 6) == 0)
>> 					PushColor(hdc, ParseColor(Start + 12));
> ****
> This really makes a very strong assumption which is almost certainly not true, that the
> specification is always 
> 	<font color="colorid">
> but it could just as easily be 
> 	<font size="3" color="colorid">
> so you really have to parse the parameters as an unordered set.
> ****
>> 			} else {
>> 				PopColor(hdc);
> ****
> Actually, you need to pop the entire font context, not just the color, because a font
> specification could change the size as well.
> ****
>> 			} /* if */
>> 			break;
>> 		default:
> ****
> What about &-escapes such as &lt;?
> ****
>> 			if (Tag == (tNONE | ENDFLAG))
>> 				break;
>> 			if (CurStyles != Styles) {
>> 				if (hfontSpecial[Styles] == NULL)
>> 					hfontSpecial[Styles] = GetFontVariant(hdc, hfontBase, Styles);
>> 				CurStyles = Styles;
>> 				SelectObject(hdc, hfontSpecial[Styles]);
>> 				/* get the width of a space character (for word spacing) */
>> 				GetTextExtentPoint32(hdc, _T(" "), 1, &size);
>> 				WidthOfSPace = size.cx;
>> 			} /* if */
>> 			/* check word length, check whether to wrap around */
>> 			GetTextExtentPoint32(hdc, Start, TokenLength, &size);
> ****
> As I learned to my dismay, this isn't really reliable for languages other than English. It
> doesn't work with certain accented characters even in English. This gets you into issues
> such as proper handling of Unicode.  You would be better off using DrawText, which should
> do the correct font computations correctly.  Generally, trying to do layout on your own is
> very risky.  Perhaps Mihai can jump in here; he's one of the Unicode layout experts.  I
> got into serious trouble trying to do word breaks in a client app, mostly because the
> client gave me a set of "critical" specs that were incompatible with the reality of
> international fonts, and it took a massive amount of effort to get them to change the
> specs to recognize the fact that their specs wouldn't work.
> **** 
>> 			if (size.cx > MaxWidth)
>> 				MaxWidth = size.cx;   /* must increase width: long non-breakable word */
>> 			if (WhiteSpace)
>> 				XPos += WidthOfSPace;
>> 			if (XPos + size.cx > MaxWidth && WhiteSpace) {
>> 				if ((uFormat & DT_WORDBREAK) != 0) {
>> 					/* word wrap */
>> 					Height += LineHeight;
>> 					XPos = 0;
>> 				} else {
>> 					/* no word wrap, must increase the width */
>> 					MaxWidth = XPos + size.cx;
>> 				} /* if */
>> 			} /* if */
>> 			/* output text (unless DT_CALCRECT is set) */
>> 			if ((uFormat & DT_CALCRECT) == 0) {
>> 				/* handle negative heights, too (suggestion of "Sims")  */
>> 				/*if (Top < 0)
>> 				{
>> 					SetRect(&rc, Left + XPos, Top - Height,
>> 					Left + MaxWidth, Top - (Height + LineHeight));
>> 				}
>> 				else*/
>> 				{
>> 					SetRect(&rc, Left + XPos, Top + Height,
>> 					Left + MaxWidth, Top + Height + LineHeight);
>> 				}
>> 				
>> 				/* reposition subscript text to align below the baseline */
>> 				DrawText(hdc, Start, TokenLength, &rc,
>> 					uFormat | ((Styles & FV_SUBSCRIPT) ? DT_BOTTOM | DT_SINGLELINE : 0));
>> 				
>> 					/* for the underline style, the spaces between words should be
>> 					* underlined as well
>> 				*/
>> 				if (WhiteSpace && (Styles & FV_UNDERLINE) && XPos >= WidthOfSPace)
>> 				{
>> 					if (Top < 0)
>> 					{
>> 						SetRect(&rc, Left + XPos - WidthOfSPace, Top - Height,
>> 							Left + XPos, Top - (Height + LineHeight));
>> 					}
>> 					else
>> 					{
>> 						SetRect(&rc, Left + XPos - WidthOfSPace, Top + Height,
>> 							Left + XPos, Top + Height + LineHeight);
>> 					}
>> 					DrawText(hdc, _T(" "), 1, &rc, uFormat);
>> 				} /* if */
>> 			} /* if */
>> 			/* update current position */
>> 			XPos += size.cx;
>> 			if (XPos > MinWidth)
>> 				MinWidth = XPos;
>> 			WhiteSpace = FALSE;
>>     } /* if */
>> 	
>>     Start += TokenLength;
>>   } /* for */
>>
>>   RestoreDC(hdc, SavedDC);
>>   for (Index = 1; Index < FV_NUMBER; Index++) /* do not erase 
>> hfontSpecial[0] */
>> 	  if (hfontSpecial[Index] != NULL)
>> 		  DeleteObject(hfontSpecial[Index]);
> ***
> This is where you should set the handles to NULL.  Not at the beginning.
> 
> Overall, there are a huge number of potential problems here as soon as you move outside
> English, and the issue of height and word break needs to be treated in a more
> culturally-neutral fashion.
> ***
>> 	
>> 	  /* store width and height back into the lpRect structure */
>> 	  if ((uFormat & DT_CALCRECT) != 0 && lpRect!=NULL) {
>> 		  lpRect->right = lpRect->left + MinWidth;
>> 		  if (lpRect->top < 0)
>> 			  lpRect->bottom = lpRect->top - (Height + LineHeight);
>> 		  else
>> 			  lpRect->bottom = lpRect->top + Height + LineHeight;
>> 	  } /* if */
>> 	
>> 	  return Height;
>> }
>>
>>
>>
>>
>> Joseph M. Newcomer a �crit :
>>> On Mon, 20 Aug 2007 15:05:43 +0200, mosfet <john.doe@anonymous.org> wrote:
>>>
>>>> Hi,
>>>>
>>>> I would like to modify a function used to render some HTML and use the 
>>>> font I have choosen :
>>>>
>>>>
>>>> // C functions
>>>> int __stdcall DrawHTML(
>>>>                        HDC     hdc,        // handle of device context
>>>>                        LPCTSTR lpString,   // address of string to draw
>>>>                        int     nCount,     // string length, in characters
>>>>                        LPRECT  lpRect,     // address of structure with 
>>>> formatting dimensions
>>>>                        UINT    uFormat     // text-drawing flags
>>>> 					   )
>>>> {
>>>> ...
>>>>
>>>>
>>>> /* get the "default" font from the DC */
>>>> 	SavedDC = SaveDC(hdc);
>>> ****
>>> You do a SaveDC but not a RestoreDC?  
>>> ****
>>>> 	hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>>>> 	SelectObject(hdc, hfontBase);
>>> ****
>>> It would be easier to write
>>> 	hfontBase = ::GetCurrentObject(hdc, OBJ_FONT);
>>> and not worry about the SelectObject pair
>>> ****
>>>> 	/* clear the other fonts, they are created "on demand" */
>>>> 	for (Index = 0; Index < FV_NUMBER; Index++)
>>>> 		hfontSpecial[Index] = NULL;
>>>> 	hfontSpecial[0] = hfontBase;
>>> ****
>>> Note that if, in between times, the font which is currently selected into the DC is
>>> deleted, the old handle you have saved here will become meaningless.  Therefore, you
>>> cannot rely on the fact that this handle will still be valid at the time you use it.
>>> Better to do an array of LOGFONT values, rather than an array of HFONTs.
>>> ****
>>>> ...
>>>> }
>>>>
>>>>
>>>> Here is my code :
>>>>
>>>>
>>>> void CxListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, 
>>>> BOOL bSelected)
>>>> {
>>>>
>>>>  CFont* pOldFont  = MemDC.SelectObject( &m_font );
>>>>
>>>> DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
>>>> 			&rc,DT_LEFT|DT_WORDBREAK);
>>> ****
>>> So why do you save the font in the MemDC when you don't actually use it?  Note that the
>>> m_font handle must represent a valid font to be selected, but the line seems to have no
>>> meaning as shown in this function.  I would also suggest something like
>>> 	HDC dc = pDC->GetSafeHdc();
>>> 	if(dc == NULL)
>>> 	    return;
>>>                DrawHTML(dc, ...as above...);
>>>> }
>>>>
>>>>
>>>>
>>>> My problem is I don't know how to modify DrawHTML to take the font 
>>>> specified in DrawItem because from what I understand DrawHTML is using a 
>>>> default font :
>>>>
>>>> hfontBase = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(SYSTEM_FONT));
>>>> 	SelectObject(hdc, hfontBase);
>>>>
>>> ****
>>> I don't see the relationship of the above code to the problem.  Where is this line of
>>> code?  I also could not find any method called DrawHTML in the MSDN documentation, could
>>> you say more about where it is implemented or what it is supposed to do?
>>> 					joe
>>> ****
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>> Joseph M. Newcomer [MVP]
>>> email: newcomer@flounder.com
>>> Web: http://www.flounder.com
>>> MVP Tips: http://www.flounder.com/mvp_tips.htm
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
0
8/20/2007 3:07:44 PM
Reply:

Similar Artilces:

Reliable way to get window underneath mine?
What is a reliable way to get the window underneath mine? Say that my window is "Window A"... "Window A" is being dragged around the screen by its title bar. The mouse cursor is at x,y. I need to know if I can drop it on the window thats at x,y (not counting "Window A"). So I need to get this window handle somehow. WindowFromPoint() obviously gets "Window A". I'd rather not enumerate all the windows since that seems like a performance issue. Thanks. Somebody wrote: > What is a reliable way to get the window underneath mine? > > Say tha...

CSliderCtrl -- can't get TB_THUMBTRACK
Hello, I added a CSliderCtrl to a dialog using the Resource editor, but to my surprise there is no way in the Class Wizard to add a callback for TB_THUMBTRACK, so that I can have my app do something when the user moves the "tic". I'm prevented from adding that message to the paltry list of 3 default usable messages. Can someone explain how to get around this unexpected problem? Thanks. All of the messages that are related to a CSliderCtrl being changed come through as with a WM_HSCROLL message. void CMyDlg::OnHScroll(UINT nSBCode, UINT nPos,CScrollBar *pScrollBar) { if (...

Is it possible to get text values in a pivot table?
From this: ROW COL VAL A HD1 X B HD2 Y B HD1 Z C HD3 J A HD3 Z B HD3 R C HD1 S Get this? Var of VAL COL ROW HD1 HD2 HD3 A X Z B Z Y R C S J (If 2 rows go to same cell, would need to get maximum or first). Not with Pivot Table Let you A, B C data be A1:A7, the HDn data in B1:B7 and the other data in C1:C7 In some convenient place (I use A11) enter =A1&B1 and copy down the column (you could put this in another sheet or in a hidden column) Make the heading HD1, HD2 - I did this in F1:H1 and the row ...

Get $500 to your PAYPAL Account by just one CLICK #2
i have hidden the form of getting $500 to your PAYPAL ACCOUNT....CLICK on the IMAGE which is on the RIGHT SIDE of the website http://tricks-4u.4-all.org/ ...

can't get "sum" to add up properly
Hi, I'd appreciate any help with my problem. I have the following A B C 1 Benefit Coverage Amount Monthly Premium 2 Employee Life .21/$1,000 $67,000.00 $14.07 3 Dependent Life (if applicable) family $2.00 4 Employee AD&D .04/$1,000$67,000.00 $2.68 5 LTD 2.58/100 $1,529.00 $39.45 6 Dental family 47.86 7 Health family 48.90 8 EAP (if applicable) yes $2.20 9 ...

Font in Check Box
Is it possible to change the Font in a check box? If it's a checkbox from the control toolbox toolbar, you can go into design mode show the checkbox's properties double click on Font and change it. If the checkbox is on a userform (inside the VBE), you can show its properties and do the same thing. You also have another reply at your original post. Mon wrote: > > Is it possible to change the Font in a check box? -- Dave Peterson ...

How can I embed a font in an Excel text box?
...

Problem with getting warning banner message working in OWA
We are using Exchange 2003 with a front-end & back-end server setup and using forms based authentication. Has anyone successfully implemented a Warning banner for OWA that users have to click the OK button before getting to the login page? I have tried out the steps provided at http://www.somorita.com/E2K324seven/Ch21-OWA-WarningBanner.doc but the warning banner still doesn't show up. Would greatly appreciate if anyone has implemented could provide any information to get this working. Thanks in advance. Mark While you are looking at the logon page in IE, use the View/Source...

Email can not get through between two domains
I am new to Exchange. Sorry for stupid questions. This is my question: An office used to have an Exchange 5.5 box to manage emails for two companies A.com and B.com. Just add a new Windows SBS 2003 for A.com. Now, the SBS 2003 server is managing emails for both A.com and B.com (did by following http://support.microsoft.com/?kbid=260973). That is, a connector is created in the new server to deliver mails to B.com. After that, users at B.com can not send email to A.com users. But A.com user can send email to B.com and users in both companies can send and receive email from outside. When user...

How do get the years and days Between two dates
if you had 5/1/2006 and 2/28/2002 how would you get 4.17? If 5/1/2006 is in A1 and 2/28/2002 is in A2, then maybe: =(a1-a2)/365 or =(a1-a2)/365.25 But if you're trying to find differences between dates, you may want to take a look at =datedif(). You can find lots of info at Chip Pearson's site: http://www.cpearson.com/excel/datedif.htm (=datedif() was only documented in xl2k's help.) jhon doe wrote: > > if you had 5/1/2006 and 2/28/2002 how would you get 4.17? -- Dave Peterson ...

Cursor font?
Is there a font available that has all (or most) of the special characters used by Excel (and, perhaps, other Office apps)? I was just writing up a few notes for myself on how to make use of Text Boxes and it would be handy to include the Text Box cursor symbol (vertical line with small cross hair near the bottom). "Square Peg" <SquarePeg@Round.Hole> wrote in message news:40add4lh10t2f1p65cnhiu4ec1m9l525an@4ax.com... > Is there a font available that has all (or most) of the special > characters used by Excel (and, perhaps, other Office apps)? > > I was just writ...

How can I get AutoShapes to "chase" in PowerPoint?
I am told that it is possible to have AutoShapes chase each other in a straight line and around curves (like through a pipe) but I can't figure out how. You need to use a motion path. There's an example here http://www.pptalchemy.co.uk/PowerPoint_Motion_Path.html -- john ATSIGN PPTAlchemy.co.uk Free PPT Hints, Tips and Tutorials http://www.pptalchemy.co.uk/powerpoint_hints_and_tips_tutorials.html "John-Novatec" wrote: > I am told that it is possible to have AutoShapes chase each other in a > straight line and around curves (like th...

How to get the Network Utilization?
In the Task Manager of Windows System, we can see the Network Utilization of the local connection. But how to get the percentage through my own program? Thanks in advance! ...

How to get weekly open high low close from a range of data?
Hello, I've set up a spreadsheet to download mutual fund prices daily from a certain website and have stored up quite an amount of data already. Now I want to use this data to produce weekly candlestick charts, so I need to get the weekly open, high, low, close from the data. The easiest way I can think of in general is to use a GROUP BY query to extract all such data from the data range, but I don't know how to set up such a query in Excel. Anyone out there can tell me? Thank you very much. Herbert if you have daily dates in column a, and the open, hi, lo, close i columns b-e...

Simple Javascript to get the current CRM user
I'm looking to add an OnChange event to restrict changes to a certain picklist field in the Account table. Simple logic, except I can't seem to figure out who the current user is... This has to be a simple one for you JavaScript jocks, and I'd really appreciate your saving me hours... Many thanks, Dave ...

Macros get disconnected
Hi All I would be very grateful for a little guidance over an issue that is puzzling me. I have a template with a number of macros attached. When I send the template by email to my co-worker, some of the macros don't appear on the form field's "Run macro on Entry or Exit". The macros do appear, however, in the Visual Basic editor. The template works perfectly well, until it is unprotected an edited. Thereafter, those form field that have "lost" the macro name/limk from their form fields don't work anymore. So, as long as the macros in the templ...

I need to get week start and week end dates to change automatically
I'm trying to get the week start and week end dates to chang automatically on a time sheet that I am working on. Anybody have formula? Joh -- Message posted from http://www.ExcelForum.com John, =INT(NOW()+2-WEEKDAY(NOW())) will return Monday's date, and =INT(NOW()+6-WEEKDAY(NOW())) will return Friday's date. Format as dates. HTH, Bernie MS Excel MVP "jlyons360 >" <<jlyons360.192pxt@excelforum-nospam.com> wrote in message news:jlyons360.192pxt@excelforum-nospam.com... > I'm trying to get the week start and week end dates to change > automa...

Simple hack to get $500 to your home. 06-03-10
Simple hack to get $500 to your home at http://dailyupdatesonly.tk Due to high security risks,i have hidden the cheque link in an image. in that website on left side below search box, click on image and enter your name and address where you want to receive your cheque.please dont tell to anyone. ...

Font Size Problems with ComboBox
The perceived font size of combo boxes in my workbook increase when I click on them, I've adjusted the zoom to 100% as the Knowledge base suggests, but I still have the same problem - is there any way around this? Please help! Stewart ...

where do i get info on how to use excel?
i don't have a manual or anything. can i buy one? is there a college course or something? hi, all of the above. most good book stores with have an excel for dummys book. microsoft site has books for all version. college course tend to be generic and way too short. books are better. and cheaper. the net is a good source too. try these sites http://www.mvps.org/dmcritchie/excel/excel.htm#tutorials http://www.j-walk.com/ss/books/xlbook25.htm http://www.cpearson.com/excel/KeyboardShortcuts.htm http://www.contextures.com/ http://www.mrexcel.com http://www.rondebruin.nl/ and you can hang ar...

Asking for help getting vlookup to work
Hello, I'm wondering if someone can help. Here is a workbook that I'm testing out vlookup in: http://download572.mediafire.com/itzzmmxemjjg/bmmyyemwkim/vlookup_book.xlsx As you can see, column C has the vlookup functions and they all use the text in the cell to the left of it as the lookup value and the same table_array. C2 and C3 have found a match but C1 hasn't. The lookup value for C1 and C2 look the same except that the one for C1 is derived from a formula and the one for C2 is entered in manually. My end goal is to get the vlookup in C1 to find a match just like C2. Any he...

Can't get Vista recovery CD to recognize installation
I'm trying to get a Powerspec B647 Vista64 Business PC to boot. After booting to the Vista Recovery CD and choosing to repair, the process can't find any installed O/S. So I press the Load Drivers button to load the B647 RAID controller drivers, which I downloaded from Powerspec to my flash drive. After pointing it to the "sataraid" folder, the system installs some controllers and drivers but still doesn't find my Vista installation afterwards. Even worse, the C drive letter is given to one of the removable media drives. After pressing the Next button I'...

Font and Symbol problems
I would appreciate help if anyone has a solution for this. I'm using Word 2004 on Leopard. I'm trying to translate old english, and i found that the Hoefler Text has a few letters and symbols I need - the problem being that word won't read them.<br> <br> I have tried going to Insert and Symbol, but when i insert the symbol i need, all i get is a box where the character should be. I opened Font Book and it says that the Hoefler font is installed.<br> <br> the 'ae' and 'AE' symbols work [the ones where both letters are conjoined].<br> <...

Foreign fonts (special characters) not shown in word/excel
Hi! I work a lot with Hungarian translations at the moment. There are 2 characters that are not shown in office documents (neither 98 nor 2001). The characters missing are the "o" and "u" with "Doppel-Akut". Their unicodes are 337 and 369. The characters are shown without any problem on the PC. We need to put the Hungarian translations into QuarkXpress. Even if I copy the text out of a PDF the characters are already missing in the clipboard. Apparently, there is an Office multilanguage kit for Mac that installs the Arial font completely new so that all characte...

Font size in Access 2003 3 x 7 label report
Using the Label Wizard to design Avery J8560 3 column, 7 row address labels the default font is Arial 8. If I change it to Arial 12, then in the preview there is not room to add all the address fields. However if I design the label with Arial 8 and then change the font to 12 in design view it all fits on the label no problem. Am I doing something wrong? ...