Thread: Font height when printing

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Font height when printing

    I can't seem to get this right...When i print a document, the lines overlap:
    Code:
    if((pDC = CreateDC("WINSPOOL", achPrinter, 0, 0))){//OK
      //A4: W=21000, H=29700
      ZeroMemory(&dInf, sizeof(DOCINFO));
      dInf.cbSize = sizeof(DOCINFO);
      dInf.lpszDocName = "PrtTest";
      if(SetTextAlign(pDC, TA_LEFT|TA_TOP)==GDI_ERROR) GetErr("SetTextAlign");
        if(StartDoc(pDC, &dInf)<=0) GetErr("StartDoc");
          if(StartPage(pDC)<=0) GetErr("StartPage");
            if((hFont = GetCurrentObject(pDC,OBJ_FONT))){
             if(GetObject(hFont,sizeof(LOGFONT),&lf)){
              lpHeight = GetDeviceCaps(pDC,VERTRES),//get height of page
              lpWidth = GetDeviceCaps(pDC,HORZRES),//and its width too
              lfH = lf.lfHeight;
              lfW = lf.lfWidth;
            }else
              GetErr("GetObject(hFont,sizeof(LOGFONT),&lf)");
          }else
            GetErr("GetCurrentObject(pd.hDC,OBJ_FONT)");
          // Kundeinfo
            if(rs.GetData("navn", p1, 50))		TextOut(pDC, 10*lfW, 2*lfH, p1, strlen(p1));
    					if(rs.GetData("adresse1", p1, 50))TextOut(pDC, 10*lfW, 3*lfH, p1, strlen(p1));
    					if(rs.GetData("round", p1, 50))		TextOut(pDC, 1000, 3*lfH, p1, strlen(p1));
    					if(rs.GetData("pnr", p1, 50))			TextOut(pDC, 10*lfW, 4*lfH, p1, strlen(p1));
    					if(rs.GetData("psted", p1, 50))		TextOut(pDC, 500, 4*lfH, p1, strlen(p1));
    					if(rs.GetData("kunnr", p1, 50))		TextOut(pDC, 800, 5*lfH, p1, strlen(p1));
    					if(rs.GetData("round", p1, 50))		TextOut(pDC, 1000, 5*lfH, p1, strlen(p1));
    					// 
    					if(EndPage(pDC)<=0) GetErr("EndPage");
    					if(EndDoc(pDC)<=0) GetErr("EndDoc");
    					DeleteDC(pDC);
    					b(hwThis, "Dokument sendt til printer", "Test", MB_ICONINFORMATION);
    				}else
    					GetErr("CMD_PRINT->GetDC()");
    Last edited by knutso; 12-04-2003 at 07:58 AM.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    have a look at

    GetTextMetrics(hdc,&tm);

    //this function will calculate the required size for a given text string (sBuffer)
    GetTextExtentPoint32 (hdc, sBuffer, lstrlen(sBuffer), &size);

    or

    Look at

    DrawText()

    first get it to calculate the area needed with the DT_CALCRECT flag
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I figured it out.
    Code:
    lHPrMm = GetDeviceCaps(pDC,VERTRES)/GetDeviceCaps(pDC,VERTSIZE),//Get height units per mm
    lWPrMm = GetDeviceCaps(pDC,HORZRES)/GetDeviceCaps(pDC,HORZSIZE);//Get width units per mm
    Then i just use:
    Code:
    TextOut(pDC, mmFromLeft*lWPrMm, mmFromTop*lHPrMm, p1, strlen(p1));

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  2. problem with my font manager
    By hannibar in forum C Programming
    Replies: 1
    Last Post: 03-07-2006, 08:03 AM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM