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

Hybrid View

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

    [RESOLVED] Font Help

    I have an application that provides a preview of the RTF files it generates. The preview renders each page using combinations of the Times Roman and Courier New fonts with a size of 8 points.

    Problem:
    The size of the Courier New text is rendered larger than the Times Roman text which results in the text exceeding the page rectangle.

    If I render everything in Times Roman at 8 point it matches the output from Word (My Output Reference) within a mm or so over the page length. If I render the data using Courier New I exceed the page length by 8 lines on the display.

    Printing also produces a variation in text length but due to the higher printer resolution it is not as great.

    I have looked at the values of the screen resolution using GetDeviceCaps(LOGPIXELSY) which returns the default 96 pixels per inch.

    Using the GetDeviceCaps(VERTRES) and (VERTSIZE) I get a resolution of 91 or 76 depending on the display.

    Using these resolutions improves reduces the height of the text but still not enough to achieve the required representation.

    I've also tried CreateFontIndirect and CreatePointFont to see if this makes a difference which unfortunately it hasn't.

    Can anyone provide some insight into a reliable method to correctly display Courier New fonts with the same accuracy as the other true type fonts.
    Please advise of solution it makes it easier to find an answer.

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

    Re: Font Help

    The two images that demonstrate my issue.


    The first image contains the lower portion of two printed versions. The Top most is the output generated using Word. Whilst the lower most is the same page printed fropm my application. The bottom of the columns with repect to the footer (Issue xx...) shows the variation in text sizes between the two.

    The second image shows the same page rendered by my application with the colum data extending below the page and over writing the footer.


    As detailed in many references and guides, "the majority of time you will spend formating output when utilising the MFC SDI/MDI printing interfaces." For this project they sure have this right.
    Attached Images Attached Images   
    Please advise of solution it makes it easier to find an answer.

  3. #3
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539

    Re: Font Help

    Can you post/email code you are using in GEtDeviceCaps() and CreateFont()...
    Jim
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

  4. #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.

  5. #5
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539

    Re: Font Help

    Looks close to what I use in my programs...

    Code:
    	pDC = GetDC();
    	int iLogPixY = GetDeviceCaps(pDC->m_hDC, LOGPIXELSY);
    	ReleaseDC(pDC);
    
    
    	memset(&lf, 0, sizeof(LOGFONT));
    	lf.lfHeight = -MulDiv(iDefFontSize, iLogPixY, 72);
    	lf.lfWidth = 0;
    	lf.lfItalic = 0;
    	lf.lfWeight = FW_NORMAL;
    	lf.lfOutPrecision = OUT_TT_PRECIS;
    	lf.lfQuality = PROOF_QUALITY;
    	lf.lfCharSet = DEFAULT_CHARSET;
    	strcpy(lf.lfFaceName, szDefFontName);
    	pCFont.CreateFontIndirect(&lf);
    Jim
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

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

    Re: Font Help

    I've search many online resources for an answer but I can't seem to find one.

    I don't know if changing the Map Mode to WW_TWIPS would help but it appears that Word uses twips to define all size data it may be a hint.

    Will need to look further.
    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