コード例 #1
0
ファイル: ex_7_8.c プロジェクト: pengliang/exercises
void PrintFiles(FILE *fp, char *file_name) {
  int line_num = 0, page_num = 0, len = 0;
  char *line = NULL;

  line_num = PrintPageHeader(file_name, ++page_num);

  while (getline(&line, &len, fp) != -1) {
    if (line_num == 1) {
      putchar('\f');
      line_num = PrintPageHeader(file_name, ++page_num);
    }

    puts(line);

    if (++line_num > kMaxPage - kMaxBottom) {
      line_num = 1;
    }
  }
  putchar('\f');
}
コード例 #2
0
void CvSqlQueryLowerView::DoFilePrint()
{
	CDC dc;
	CPrintDialog printDlg(FALSE);

	if (printDlg.DoModal() == IDCANCEL)         // Get printer settings from user
		return;

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

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

	DOCINFO di;                                 // Initialise print document details
	::ZeroMemory (&di, sizeof (DOCINFO));
	di.cbSize = sizeof (DOCINFO);
	di.lpszDocName = strTitle;

	BOOL bPrintingOK = dc.StartDoc(&di);        // Begin a new print job
	// Get the printing extents and store in the m_rectDraw field of a  CPrintInfo object
	CPrintInfo Info;
	Info.m_rectDraw.SetRect(0,0, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES));
	Info.m_bPreview = TRUE;

	OnBeginPrinting(&dc, &Info);                // Call your "Init printing" funtion
	if (m_nPageWidth > Info.m_rectDraw.Width())
		m_nPageWidth = Info.m_rectDraw.Width();
	if (m_nPageHeight > Info.m_rectDraw.Height())
		m_nPageHeight = Info.m_rectDraw.Height();

	while (bPrintingOK)
	{
		dc.StartPage();                         // begin new page
		PrintPageHeader(&dc, Info.m_nCurPage);  // updates m_nHeaderHeight
		PrintPageFooter(&dc, Info.m_nCurPage);  // updates m_nFooterHeight

		ASSERT (m_nHeaderHeight >= 0);
		ASSERT (m_nFooterHeight >= 0);

		PrintPage(&dc, Info.m_nCurPage);
		Info.m_nCurPage++;
		dc.EndPage();
		bPrintingOK = ((int)Info.m_nCurPage > m_nbPrintPage) ? FALSE: TRUE;
	}

	OnEndPrinting(&dc, &Info);
	dc.EndDoc();
	dc.Detach();
}
コード例 #3
0
void CvSqlQueryLowerView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	// Pre-adjust width and height
	if (m_nPageWidth > pInfo->m_rectDraw.Width())
		m_nPageWidth = pInfo->m_rectDraw.Width();
	if (m_nPageHeight > pInfo->m_rectDraw.Height())
		m_nPageHeight = pInfo->m_rectDraw.Height();

	PrintPageHeader(pDC, pInfo->m_nCurPage);  // updates m_nHeaderHeight
	PrintPageFooter(pDC, pInfo->m_nCurPage);  // updates m_nFooterHeight

	ASSERT (m_nHeaderHeight >= 0);
	ASSERT (m_nFooterHeight >= 0);

	PrintPage(pDC, pInfo->m_nCurPage);
}
コード例 #4
0
void CScribbleView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	if (pInfo->m_nCurPage == 1)  // page no. 1 is the title page
	{
		PrintTitlePage(pDC, pInfo);
		return; // nothing else to print on page 1 but the page title
	}
	CString strHeader = GetDocument()->GetTitle();

	PrintPageHeader(pDC, pInfo, strHeader);
	// PrintPageHeader() subtracts out from the pInfo->m_rectDraw the
	// amount of the page used for the header.

	pDC->SetWindowOrg(pInfo->m_rectDraw.left,-pInfo->m_rectDraw.top);

	// Now print the rest of the page
	OnDraw(pDC);
}
コード例 #5
0
ファイル: listing.c プロジェクト: cc65/cc65
static void PrintLine (FILE* F, const char* Header, const char* Line, const ListLine* L)
/* Print one line to the listing file, adding a newline and counting lines */
{
    /* Print the given line */
    fprintf (F, "%s%s\n", Header, Line);

    /* Increment the current line */
    ++PageLines;

    /* Switch to a new page if needed. Do not switch, if the current line is
    ** the last one, to avoid pages that consist of just the header.
    */
    if (PageLength > 0 && PageLines >= PageLength && L->Next != 0) {
        /* Do a formfeed */
        putc ('\f', F);
        /* Print the header on the new page */
        PrintPageHeader (F, L);
    }
}
コード例 #6
0
ファイル: WorkspaceView.cpp プロジェクト: malpharo/AiPI
void CWorkspaceView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	CFont font;

	CWorkspaceTabDoc* pDoc = GetDocument();
	m_nPage = pInfo->m_nCurPage; // en beneficio de PrintPageFooter
    
	// fuente de 14 puntos, tamaño fijo
	font.CreateFont(-30, 0, 0, 0, 400, FALSE, FALSE,
	                0, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
	                CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
	                DEFAULT_PITCH | FF_MODERN, _T("Arial"));
	                // Courier New es una fuente TrueType 
    CFont* pOldFont = (CFont*) (pDC->SelectObject(&font));
    
        
	PrintPageHeader(pDC);
	PrintPageFooter(pDC); 
	
	pDC->SelectObject(pOldFont);
	
	
	WORKSPACEMAINVIEW::OnPrint(pDC, pInfo);
}
コード例 #7
0
ファイル: listing.c プロジェクト: cc65/cc65
void CreateListing (void)
/* Create the listing */
{
    FILE* F;
    Fragment* Frag;
    ListLine* L;
    char HeaderBuf [LINE_HEADER_LEN+1];

    /* Open the real listing file */
    F = fopen (SB_GetConstBuf (&ListingName), "w");
    if (F == 0) {
        Fatal ("Cannot open listing file '%s': %s",
               SB_GetConstBuf (&ListingName),
               strerror (errno));
    }

    /* Reset variables, print the header for the first page */
    PageNumber = 0;
    PrintPageHeader (F, LineList);

    /* Terminate the header buffer. The last byte will never get overwritten */
    HeaderBuf [LINE_HEADER_LEN] = '\0';

    /* Walk through all listing lines */
    L = LineList;
    while (L) {

        char* Buf;
        char* B;
        unsigned Count;
        unsigned I;
        char* Line;

        /* If we should not output this line, go to the next */
        if (L->Output == 0) {
            L = L->Next;
            continue;
        }

        /* If we don't have a fragment list for this line, things are easy */
        if (L->FragList == 0) {
            PrintLine (F, MakeLineHeader (HeaderBuf, L), L->Line, L);
            L = L->Next;
            continue;
        }

        /* Count the number of bytes in the complete fragment list */
        Count = 0;
        Frag = L->FragList;
        while (Frag) {
            Count += Frag->Len;
            Frag = Frag->LineList;
        }

        /* Allocate memory for the given number of bytes */
        Buf = xmalloc (Count*2+1);

        /* Copy an ASCII representation of the bytes into the buffer */
        B = Buf;
        Frag = L->FragList;
        while (Frag) {

            /* Write data depending on the type */
            switch (Frag->Type) {

                case FRAG_LITERAL:
                    for (I = 0; I < Frag->Len; ++I) {
                        B = AddHex (B, Frag->V.Data[I]);
                    }
                    break;

                case FRAG_EXPR:
                case FRAG_SEXPR:
                    B = AddMult (B, 'r', Frag->Len*2);
                    break;

                case FRAG_FILL:
                    B = AddMult (B, 'x', Frag->Len*2);
                    break;

                default:
                    Internal ("Invalid fragment type: %u", Frag->Type);

            }

            /* Next fragment */
            Frag = Frag->LineList;

        }

        /* Limit the number of bytes actually printed */
        if (L->ListBytes != 0) {
            /* Not unlimited */
            if (Count > L->ListBytes) {
                Count = L->ListBytes;
            }
        }

        /* Output the data. The format of a listing line is:
        **
        **      PPPPPPm I  11 22 33 44
        **
        ** where
        **
        **      PPPPPP  is the PC
        **      m       is the mode ('r' or empty)
        **      I       is the include level
        **      11 ..   are code or data bytes
        */
        Line = L->Line;
        B    = Buf;
        while (Count) {

            unsigned    Chunk;
            char*       P;

            /* Prepare the line header */
            MakeLineHeader (HeaderBuf, L);

            /* Get the number of bytes for the next line */
            Chunk = Count;
            if (Chunk > 4) {
                Chunk = 4;
            }
            Count -= Chunk;

            /* Increment the program counter. Since we don't need the PC stored
            ** in the LineList object for anything else, just increment this
            ** variable.
            */
            L->PC += Chunk;

            /* Copy the bytes into the line */
            P = HeaderBuf + 11;
            for (I = 0; I < Chunk; ++I) {
                *P++ = *B++;
                *P++ = *B++;
                *P++ = ' ';
            }

            /* Output this line */
            PrintLine (F, HeaderBuf, Line, L);

            /* Don't output a line twice */
            Line = "";

        }

        /* Delete the temporary buffer */
        xfree (Buf);

        /* Next line */
        L = L->Next;

    }

    /* Close the listing file */
    (void) fclose (F);
}