Fontgröße in Printfunktion



  • Hallo, vielleicht kann mir jemand sagen, wie ich die Fontgröße (z.B. 10 P) in der Methode "SendPrinter" festlege.

    Mein Code sieht so aus:

    void CSendOrder::SendPrinter() {

    CDC dc;
    CPrintDialog printDlg(FALSE);
    CRect r;
    int nHeight;
    CString tmp;

    tmp = m_messagebody;
    tmp.Replace("%0A","\r\n");

    // ask the user to select a printer
    if (printDlg.DoModal() == IDCANCEL)
    return;

    // Attach a printer DC
    dc.Attach(printDlg.GetPrinterDC());
    dc.m_bPrinting = TRUE;

    // use Textmappingmode, that's easiest to map the fontsize
    dc.SetMapMode(MM_TEXT);

    // setup font specifics
    LOGFONT LogFont;

    CFont aFont, *oldFont;

    LogFont.lfHeight = -MulDiv(10, GetDeviceCaps(dc, LOGPIXELSY), 72);
    LogFont.lfWidth = 0;
    LogFont.lfEscapement = 0;
    LogFont.lfOrientation = 0;
    LogFont.lfWeight = 0;
    LogFont.lfItalic = false;
    LogFont.lfUnderline = 0;
    LogFont.lfStrikeOut = 0;
    LogFont.lfCharSet = ANSI_CHARSET;
    LogFont.lfOutPrecision = OUT_TT_PRECIS;
    LogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    LogFont.lfQuality = DEFAULT_QUALITY;
    LogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
    lstrcpy (LogFont.lfFaceName, "Arial");
    dc.SetBkMode(OPAQUE);
    aFont.CreateFontIndirect ( &LogFont );
    // ok, we've build the font, now use it
    oldFont = dc.SelectObject( &aFont );

    // Get the application title
    CString strTitle;
    strTitle.LoadString(AFX_IDS_APP_TITLE);

    // Initialise print document details

    DOCINFO di;
    ::ZeroMemory (&di, sizeof (DOCINFO));
    di.cbSize = sizeof (DOCINFO);
    // application title appears in the spooler view
    di.lpszDocName = strTitle;

    // Begin a new print job
    BOOL bPrintingOK = dc.StartDoc( &di );

    // Get the printing extents and store in the m_rectDraw field of a
    // CPrintInfo object
    CPrintInfo Info;
    int w = dc.GetDeviceCaps(HORZRES);
    int h = dc.GetDeviceCaps(VERTRES);
    Info.m_rectDraw.SetRect(0,0, w, h);

    char *startAt = tmp.GetBuffer(0);
    int totalDone = 0;
    int lengthToGo = tmp.GetLength();

    for (UINT page = Info.GetMinPage(); bPrintingOK && (totalDone < lengthToGo); page++)
    {
    // begin new page
    dc.StartPage();
    Info.m_nCurPage = page;

    // calc how much text fits on one page
    r = Info.m_rectDraw;
    r.bottom = r.top;
    int i = 0;
    while ( (r.bottom < Info.m_rectDraw.bottom) && (totalDone + i < lengthToGo))
    {
    r.right = Info.m_rectDraw.right;
    nHeight = dc.DrawText(startAt, i++, r,
    DT_CALCRECT|DT_WORDBREAK|DT_NOCLIP|DT_EXPANDTABS);
    }
    // go one back to assure correct height
    if (r.bottom >= Info.m_rectDraw.bottom)
    i--;

    // print that text
    dc.DrawText(startAt, i, r, DT_WORDBREAK|DT_NOCLIP|DT_EXPANDTABS);

    // go to next page
    startAt += i;
    totalDone += i;

    // end page
    bPrintingOK = (dc.EndPage() > 0);

    }

    // end a print job
    if (bPrintingOK)
    dc.EndDoc();
    else
    // abort job.
    dc.AbortDoc();

    // restore font
    dc.SelectObject(oldFont);
    // free font memory
    aFont.DeleteObject();
    // detach the printer DC
    dc.Detach();
    };



  • Entweder hab ich die "Frage" nicht verstanden oder es ist schon wieder April 🤡

    // FONTGROESSE berechnen und eintragen (umrechnen auf die Auflösung des Devices)
    LogFont.lfHeight = -MulDiv(10, GetDeviceCaps(dc, LOGPIXELSY), 72);
    LogFont.lfWidth = 0;
    LogFont.lfEscapement = 0;
    LogFont.lfOrientation = 0;
    LogFont.lfWeight = 0;
    LogFont.lfItalic = false;
    LogFont.lfUnderline = 0;
    LogFont.lfStrikeOut = 0;
    LogFont.lfCharSet = ANSI_CHARSET;
    LogFont.lfOutPrecision = OUT_TT_PRECIS;
    LogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    LogFont.lfQuality = DEFAULT_QUALITY;
    LogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
    lstrcpy (LogFont.lfFaceName, "Arial");
    dc.SetBkMode(OPAQUE);
    aFont.CreateFontIndirect ( &LogFont ); // Font erzeugen
    // ok, we've build the font, now use it
    oldFont = dc.SelectObject( &aFont );  // Font in das DC eintragen
    

    Siehe Kommentare im Source. Erklär doch mal bitte Dein Problem 🤡

    Tip: Mit Code Tags schaut Dein Quelltext übersichtlicher aus.


Anmelden zum Antworten