📄 text.c
字号:
if (TextOutA(pData->hDC,
CurrentCol * CharWidth,
CurrentLine * CharHeight,
pLineBuffer,
Length) == FALSE) {
ODS(("TextOut() failed\n"));
bAbortDoc = TRUE;
goto Done;
}
CurrentCol += Length;
}
/**
Even if the length is zero, increment the line.
Should happen when the character is only 0x0D or 0x0A.
**/
if (fdwFlags & FLAG_CR) {
CurrentCol=0;
fdwFlags &= ~FLAG_CR;
}
if (fdwFlags & FLAG_LF) {
CurrentLine++;
fdwFlags &= ~FLAG_LF;
}
/**
We need a new page. Set the current line to the
end of the page. We could do a End/StartPage
sequence, but this may cause a blank page to get
ejected.
Note: this code will avoid printing out pages that
consist of formfeeds only (if you have a page with a
space in it, that counts as text).
**/
if (fdwFlags & FLAG_FF) {
CurrentLine = LinesPerPage;
CurrentCol = 0;
fdwFlags &= ~FLAG_FF;
}
/**
We have done the text out, so these characters have
been successfully printed. Zero out Length
so these characters won't be printed again
**/
Length = 0;
/**
We only terminate this loop if we run out of chars
or we run out of read buffer.
**/
} while (pReadBuffer && pReadBuffer != pReadBufferEnd);
/** Keep going until we get the last line **/
} while (!ReadAll);
if (EndPage(pData->hDC) == SP_ERROR) {
bAbortDoc = TRUE;
goto Done;
}
/**
Close the printer - we open/close the printer for each
copy so the data pointer will rewind.
**/
ClosePrinter(hPrinter);
hPrinter = NULL;
} /* While copies to print */
/** Let the printer know that we are done printing **/
EndDoc(pData->hDC);
ReturnValue = TRUE;
Done:
if (hPrinter)
ClosePrinter(hPrinter);
if (bAbortDoc)
AbortDoc(pData->hDC);
if (pLineBuffer)
FreeSplMem(pLineBuffer);
if (hOldFont)
{
SelectObject(pData->hDC, hOldFont);
DeleteObject(hFont);
}
return ReturnValue;
}
/*++
*******************************************************************
G e t T a b b e d L i n e F r o m B u f f e r
Routine Description:
This routine, given a buffer of text, will pull out a
line of tab-expanded text. This is used for tab
expansion of text data jobs.
Arguments:
pSrcBuffer => Start of source buffer.
pSrcBufferEnd => End of source buffer
pDestBuffer => Start of destination buffer
CharsPerLine => Number of characters on a line
TabExpansionSize=> Number of spaces in a tab
Encoding => Code page
pLength => Length of chars from prev line, rets current
pTabBase => New 0 offset for tabbing
pfdwFlags => State
Return Value:
PBYTE => Place left off in the source buffer. This should
be passed in on the next call. If we ran out of
data in the source, this will be unchanged.
*******************************************************************
--*/
PBYTE
GetTabbedLineFromBuffer(
IN PBYTE pSrcBuffer,
IN PBYTE pSrcBufferEnd,
IN PBYTE pDestBuffer,
IN ULONG CharsPerLine,
IN ULONG TabExpansionSize,
IN ULONG Encoding,
IN OUT PULONG pLength,
IN OUT PULONG pTabBase,
IN OUT PDWORD pfdwFlags
)
{
ULONG current_pos;
ULONG expand, i;
ULONG TabBase = *pTabBase;
ULONG TabBaseLeft = TabExpansionSize-TabBase;
PBYTE pDestBufferEnd = pDestBuffer + CharsPerLine;
/**
If the tab pushed us past the end of the last line, then we need to
add it back to the next one.
**/
if (TabBase && ( *pfdwFlags & FLAG_TAB_STATE )) {
current_pos = 0;
i=TabBase;
while (i-- && (pDestBuffer < pDestBufferEnd)) {
*pDestBuffer++ = ' ';
current_pos++;
}
/**
If we ran out of room again, return. This means that
the tab expansion size is greater than we can fit on
one line.
**/
if (pDestBuffer >= pDestBufferEnd) {
*pLength = current_pos;
pTabBase -= CharsPerLine;
//
// We need to move to the next line.
//
*pfdwFlags |= FLAG_LF | FLAG_CR;
return pSrcBuffer;
}
*pfdwFlags &= ~FLAG_TAB_STATE;
} else {
/** We may have some chars from the previous ReadPrinter **/
current_pos = *pLength;
pDestBuffer += current_pos;
}
while (pSrcBuffer < pSrcBufferEnd) {
/** Now process other chars **/
switch (*pSrcBuffer) {
case 0x0C:
/** Found a FF. Quit and indicate we need to start a new page **/
*pTabBase = 0;
*pfdwFlags |= FLAG_FF;
*pfdwFlags &= ~FLAG_CR_STATE;
pSrcBuffer++;
break;
case '\t':
*pfdwFlags &= ~FLAG_CR_STATE;
/**
Handle TAB case. If we are really out of buffer,
then defer now so that the tab will be saved for
the next line.
**/
if (pDestBuffer >= pDestBufferEnd) {
goto ShiftTab;
}
pSrcBuffer++;
/** Figure out how far to expand the tabs **/
expand = TabExpansionSize -
(current_pos + TabBaseLeft) % TabExpansionSize;
/** Expand the tabs **/
for (i = 0; (i < expand) && (pDestBuffer < pDestBufferEnd); i++) {
*pDestBuffer++ = ' ';
}
/**
If we reached the end of our dest buffer,
return and set the number of spaces we have left.
**/
if (pDestBuffer >= pDestBufferEnd) {
*pfdwFlags |= FLAG_TAB_STATE;
goto ShiftTab;
}
/** Update our position counter **/
current_pos += expand;
continue;
case 0x0A:
pSrcBuffer++;
/** If the last char was a CR, ignore this guy **/
if (*pfdwFlags & FLAG_CR_STATE) {
*pfdwFlags &= ~FLAG_CR_STATE;
//
// We are translating CRLF, so if we saw a CR
// immediately before this, then don't do anything.
//
continue;
}
if( *pfdwFlags & FLAG_TRANSLATE_LF ){
//
// If we are translating, then treat a LF as a CRLF pair.
//
*pfdwFlags |= FLAG_LF | FLAG_CR;
/** Found a linefeed. That's it for this line. **/
*pTabBase = 0;
} else {
*pfdwFlags |= FLAG_LF;
}
break;
case 0x0D:
/** Found a carriage return. That's it for this line. **/
*pTabBase = 0;
pSrcBuffer++;
if (*pfdwFlags & FLAG_TRANSLATE_CR) {
//
// If we are translating CRLF, then make the newline
// occur now. This handles the case where we have a
// CR all by itself. Also set the CR flag so if there
// happens to be a LF immediately after this, we don't
// move down another line.
//
*pfdwFlags |= FLAG_CR_STATE | FLAG_LF | FLAG_CR;
} else {
*pfdwFlags |= FLAG_CR;
}
break;
default:
/** Not tab or carriage return, must be simply data **/
*pfdwFlags &= ~FLAG_CR_STATE;
//
// We always check before we are adding a character
// (instead of after) since we may be at the end of a line,
// but we can still process chars like 0x0d 0x0a.
// This happens in MS-DOS printscreen.
//
if (pDestBuffer >= pDestBufferEnd ||
(pDestBuffer + 1 >= pDestBufferEnd) &&
IsDBCSLeadByteEx(Encoding, *pSrcBuffer)) {
ShiftTab:
//
// We must shift the tab over since we are on the
// same line.
//
*pTabBase = (*pTabBase + TabExpansionSize -
(CharsPerLine % TabExpansionSize))
% TabExpansionSize;
*pfdwFlags |= FLAG_LF | FLAG_CR;
break;
}
if (IsDBCSLeadByteEx(Encoding, *pSrcBuffer)) {
// Check if we have trail byte also.
if (pSrcBuffer + 1 >= pSrcBufferEnd) {
*pfdwFlags |= FLAG_DBCS_SPLIT;
break;
}
// Advance source pointer (for lead byte).
*pDestBuffer++ = *pSrcBuffer++;
current_pos++;
}
*pDestBuffer++ = *pSrcBuffer++;
current_pos++;
continue;
}
*pLength = current_pos;
return pSrcBuffer;
}
/** We ran out of source buffer before getting to the EOL **/
*pLength = current_pos;
return NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -