CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 31

Threaded View

  1. #4
    Join Date
    Jul 1999
    Location
    Sth Australia, Australia
    Posts
    492

    Re: Font Help

    Below is the code used to determine the resolution of the Device used within my app.

    Code:
    int CalculateYPixels(CDC* DeviceContext)
    {
        int VertRes = DeviceContext->GetDeviceCaps(VERTRES);
        int Height = DeviceContext->GetDeviceCaps(VERTSIZE);
        float PixelsInch = (((float)VertRes / (float)Height) * 25.4) + 0.5;
    
        if(PixelsInch > 300)
            PixelsInch = DeviceContext->GetDeviceCaps(LOGPIXELSY);
    
        return (int) PixelsInch;
    }

    The following is an extract of my code that shows how each font is created.

    Code:
    	memset(&WorkingLogFont, 0, sizeof(LOGFONT));
    	DeviceContext->GetCurrentFont()->GetLogFont(&WorkingLogFont);
    
    	WorkingLogFont.lfWidth = 0;
    	WorkingLogFont.lfWeight = FW_NORMAL;
    	WorkingLogFont.lfCharSet = ANSI_CHARSET;
    	WorkingLogFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
        WorkingLogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    	WorkingLogFont.lfPitchAndFamily = FIXED_PITCH;
    
           lstrcpy(WorkingLogFont.lfFaceName, GetFontName(CellParaFont));
    
                WorkingLogFont.lfHeight = -MulDiv(GetFontSize(CellParaFont), PixelsInch, 72);
    
    	if(WorkingFont->CreateFontIndirect(&WorkingLogFont))
    	{
    		OldFont = DeviceContext->SelectObject(WorkingFont);
    	}
    CellParaFont font is a CString which represents the font face name of either "Times Roman New" or "Courier New" and the size of the font as defined in the RTF V1.6 spec. Each of the routines using this data returns the correct values.

    Stepping trough the code shows that all elements of the LogFont have been initialised with the expected values and the CreateFont indirect function return true indicating successful completion.

    Using the GetTextFace funct shows that the Courier New font is being used with the TextOut function used to generate the text.
    Last edited by sma; February 15th, 2011 at 05:04 PM.
    Please advise of solution it makes it easier to find an answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured