[RESOLVED] Font Help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 31

Thread: [RESOLVED] Font Help

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

    [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
    488

    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,538

    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
    488

    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,538

    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
    488

    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.

  7. #7
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,538

    Re: Font Help

    Quite possible they only use TWIPS....I only use MM_HIENGLISH in my programs and all looks the same if printed directly or to a PDF...
    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.

  8. #8
    Join Date
    Jul 1999
    Location
    Sth Australia, Australia
    Posts
    488

    Re: Font Help

    My APP uses the default MM_TEXT Mapping, which as stated earlier works fine for Times Roman font @ 8 point height.

    I going to test it at 10 point to see if it is infact the sizing of the font by windows.

    I think Microsoft may not be using the same techniques to scal the fonts in word as available via VC++.
    Please advise of solution it makes it easier to find an answer.

  9. #9
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,538

    Re: Font Help

    Quote Originally Posted by sma View Post
    I think Microsoft may not be using the same techniques to scal the fonts in word as available via VC++.
    Are you thinking that M$ might be holding back some functionality for their own use that is not available to Developers...would they do that ?? LOL
    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.

  10. #10
    Join Date
    Jul 1999
    Location
    Sth Australia, Australia
    Posts
    488

    Re: Font Help

    I just did a test which printed the same 15 lines of 10 point Courier New from both Word and directly to the printer from my app.

    Overall Word Heght = 56mm, My App = 53.5 meaning and additional

    3.5mm/14 = 0.25mm in line height.

    Over 61 lines Word = 240.5, My App = 225mm -> 15.5/60 = 0.258mm

    Given 1 point = 25.4/72 -> 0.352mm it is clear that some further manipulation of fon sizes is occuring.

    Also noted that the Word rendering of a page on the same display at a scale of 100% shows a with variation of 4mm, Word = 234 my app shows 230 when the LOGPIXELSX is used to for all size conversions.

    The line height in Word on the display is also larger than that printed so it is clear that some other scaling is occurring.
    Please advise of solution it makes it easier to find an answer.

  11. #11
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,538

    Re: Font Help

    So it is actually changing the font size and not the line spacing ?
    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.

  12. #12
    Join Date
    Jul 1999
    Location
    Sth Australia, Australia
    Posts
    488

    Re: Font Help

    Overlaying the two printouts it appears that the individual characters are slightly larger when printed from Word. So I would say that the font size has been manipulated in some way.

    This does prevent the printouts from matching exactly however the issue is with the screen representation and the inability to render all of the page data within the required area.

    I was considering creating a DC of the resolution of the connected printer (600 x 600) representing the page, rendering the page and then using StrBlt to reduce this to the page area drawn on the screen.

    My concern with this approach would be the clarity of the resultant text and what would I do if the end user had no printer connected?
    Please advise of solution it makes it easier to find an answer.

  13. #13
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,538

    Re: Font Help

    Let me do some testing on my system using Courier New...
    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.

  14. #14
    Join Date
    Jul 1999
    Location
    Sth Australia, Australia
    Posts
    488

    Re: Font Help

    Ok, thanks for your help I hope you come to the same conclusions.
    Please advise of solution it makes it easier to find an answer.

  15. #15
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,538

    Re: Font Help

    Quote Originally Posted by sma View Post
    Ok, thanks for your help I hope you come to the same conclusions.

    Well actually I came up with 2 printouts that are exactly the same...I printed Courier New 10pt from within Word (2001 Small Business) and a MFC App of mine (code posted above)...I then measured the height of a "I" (upper case "i")...both were .0845in or 2.15mm in height.
    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.

Page 1 of 3 123 LastLast

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center