📄 textprsr.cpp
字号:
{ pData_CHAR[indx] = ' '; //treat tab char as a tab, not a space, inside PRE text: if(('\t' == ch) && (m_pTextWindow->peekAtIsPreStack()) ) { // pretend we've found the start and end of a tag so a // new TC will be created with this char and the // next will start just after this char. { bTabCharHandled = TRUE; indexOfLeftBracket = indx; indexOfRightBracket = indexOfLeftBracket; bDealingWithTabCharWithPre = TRUE; bSomeCharsFoundSinceLastBreakTag = TRUE; bSomeCharsFoundSinceLastPosTag = TRUE; break; //indexOf[Left&Right]Bracket vars are set // to act as a fake tag just after this '\t'. } } } //Reduce any string of newlines into either one or zero spaces, // one space if !bSomeCharsFoundSinceLastBreakTag, 0 otherwise: // UNLESS we're currently between a <PRE> and a </PRE>. in which // case leave them alone. // If we are ignoring extra spaces, then do this for spaces and // tab chars, too: else if(('\n' == ch || '\r' == ch) || (m_pTextWindow->IgnoreExtraSpaces() && ((!bTabCharHandled && ('\t' == ch || '\v' == ch)) || ' ' == ch ) ) ) { LONG32 firstNewlineIndex = indx; pData_CHAR[firstNewlineIndex] = ' '; indexOfLeftBracket = indx; if(indexOfLeftBracket+1==len) { //If we're at the end of the packet and it ends with a // space or tab char and we're ignoring extra spaces, // then we want to make sure NOT to ignore this last // space if it's solo: if('\n' != ch && '\r' != ch && m_pTextWindow->IgnoreExtraSpaces()) { indexOfLeftBracket++; } } LONG32 newLineCharCount=1L;//XXXXXEH-19980918: BOOL bNonSpaceTabNewlineCharWasLastFound = FALSE; for(indx++; indx<len; indx++, newLineCharCount++) { _CHAR ch2 = pData_CHAR[indx]; if('\n' == ch2 || '\r'== ch2) { pData_CHAR[indx] = ' '; if(m_pTextWindow->peekAtIsPreStack()) // pretend we've found the start and end of a tag so // a new TC will be created with this char and the // next will start just after this char: { //See if this is a PC "\r\n" newline: if('\r' == pData_CHAR[indx-1] && '\n' == ch2) { indx++; } ulNumPREtagNewlineCharsFound++; } } else if(m_pTextWindow->IgnoreExtraSpaces() && !m_pTextWindow->peekAtIsPreStack() && (!bTabCharHandled && ('\t' == ch2 || '\v' == ch2)) ) { ; } else if(m_pTextWindow->IgnoreExtraSpaces() && !m_pTextWindow->peekAtIsPreStack() && ' ' == ch2) { ; } else {//XXXXXEH-19980918>> //C_RTRNDR_DIFF>> if(IsBeta1Player()) { break; } //END C_RTRNDR_DIFF. if('<'!=ch2) { bNonSpaceTabNewlineCharWasLastFound = TRUE; }//<<XXXXXEH-19980918. break; } } indx--; //back up one for outer for loop. if(bSomeCharsFoundSinceLastBreakTag) {//XXXXXEH-is fix for bug 4881 here?!? If UNIX uses '\n' instead of "\r\n",// and we don't handle that count==1 here, what in the Wide Wide World Of// Sports happens?? (Needs checking in same code in rtrender/c_rtrndr.cpp) //Doesn't follow a new line, so just reduce to 1 space: if(newLineCharCount >= 2L) { indexOfRightBracket = firstNewlineIndex + newLineCharCount - 1L; indexOfLeftBracket = firstNewlineIndex + 1L; bIgnoringNewlineChars = TRUE; bSomeCharsFoundSinceLastBreakTag = TRUE; break; //indexOf[Left&Right]Bracket vars are set // to act as a fake tag after the first one. } } else //we want to ignore all newline characters found // because they were preceded by a line break tag, so // pretend we've found the start and end of a tag so a new // TC will be created ending just before this char and the // next will start just after this char. { indexOfLeftBracket = firstNewlineIndex; indexOfRightBracket = firstNewlineIndex + newLineCharCount - 1L; bIgnoringNewlineChars = TRUE;//XXXXXEH-19980918>> //C_RTRNDR_DIFF>> if(IsBeta1Player()) { bSomeCharsFoundSinceLastPosTag = TRUE; bSomeCharsFoundSinceLastBreakTag = TRUE; } else //<<END C_RTRNDR_DIFF. { bSomeCharsFoundSinceLastBreakTag = bSomeCharsFoundSinceLastPosTag = bNonSpaceTabNewlineCharWasLastFound; }//<<XXXXXEH-19980918. break; //indexOf[Left&Right]Bracket vars are set. // to act as a fake tag where newlines are.. } } } if(-1L != indexOfLeftBracket && -1L == indexOfRightBracket) { //Check if we're inside an HTML-style ("<!-- ... -->") comment, // and then ignore all '>'s until we see one preceeded by "--", // i.e., only "-->" ends a comment: if(len-indexOfLeftBracket >= 4) { if(!stringCompare(&pData_CHAR[indexOfLeftBracket], 4, "<!--", 4)) { m_pTextWindow->incrementCommentTagNestCount(); } } //find the closing '>': for(indx++; indx<len; indx++) { _CHAR ch = pData_CHAR[indx];/*XXXEH- for now, we have to assume that the text encountered is not DBCS text; all text inside tags must be us-ascii charset: //added the following to handle DBCS chars: if((UCHAR)ch >= DBCS_MIN_LEAD_BYTE_VAL) { indx++; //skip this and the following trail byte. continue; }*/ if('>' == ch) { //Check if we're inside an HTML-style ("<!-- ... -->") // comment, which could contain a '>' (which should be // ignored) before the closing "-->": if(m_pTextWindow->getCommentTagNestCount()) { if(indx-startIndex >= 2) { if(!stringCompare(&pData_CHAR[indx-2], 3, "-->", 3)) { if(m_pTextWindow-> decrementCommentTagNestCount() > 0L) { continue; //we're still inside a nested // comment. } } else { continue; } } } indexOfRightBracket = indx; //Added this to make this XML-compatible: if(indexOfRightBracket>0) { if(pData_CHAR[indexOfRightBracket-1] == '/') { bSlashFoundAtEndOfTag = TRUE; pData_CHAR[indexOfRightBracket-1] = ' '; } } break; } else if('<' == ch && m_pTextWindow->getCommentTagNestCount()) { //Check if we're a comment nested inside another // ("<!-- ... -->") comment: if(len-indx >= 4) { if(!stringCompare(&pData_CHAR[indx], 4, "<!--", 4)) { m_pTextWindow->incrementCommentTagNestCount(); } } } //Convert any newline or tab chars to spaces: if('\n' == ch || '\r' == ch || '\t' == ch || '\v' == ch || '\0' == ch) { pData_CHAR[indx] = ' '; //Note: don't need to track #of conversions inside tag } } if(-1 == indexOfRightBracket) { //No valid end-of-tag found, so ignore all text from // indexOfLeftBracket on; this is done by putting a '\0' // at pData_CHAR[indexOfLeftBracket]: pData_CHAR[indexOfLeftBracket] = '\0'; len = indexOfLeftBracket - startIndex; } } LONG32 tempLen; BOOL bPreTabOrNewlineCharOnly = FALSE; if(indexOfLeftBracket != -1) { tempLen = indexOfLeftBracket - startIndex; pData_CHAR[indexOfLeftBracket] = '\0'; if(!tempLen) { //Special case where a tab char was the only text found // between tags, and, since we're faking like a PRE tab // is a tag, tempLen ended up 0 and the while loop, below, // was not getting entered: if(bDealingWithTabCharWithPre) { bPreTabOrNewlineCharOnly = TRUE; } } } else { tempLen = len - startIndex; } ulCurCharset = m_pTextWindow->peekAtCharsetStack(); //Added the following "while" to allow for // word wrap; break the text up wherever there is a // space char. (Also, Changed "if(tempLen.." to // "while(tempLen.." ULONG32 tmpStartIndex = startIndex; while(tempLen > 0 || bPreTabOrNewlineCharOnly) { ULONG32 theFollowingSpaceCharIndex = tempLen; char savedChar = '\0'; _CHAR* pCurText = &pData_CHAR[tmpStartIndex]; //C_RTRNDRDIFF >>: //this needs to be reset prior to the creation of each T.C.: BOOL bCurLineHasREQUIREDContents = FALSE; //<< END C_RTRNDRDIFF. if(m_pTextWindow->usingWordwrap() && !m_pTextWindow->peekAtIsPreStack()) { //Allow wordwrap to happen in DBCS/UNICODE between chars, not // just where spaces are, because each character represents // a "word" and they are rarely separated by spaces: //XXXEH- NOTE: I assume that UNICODE characters that have a // zero-valued first byte are really SBCS characters and // should not get wordwrapped (because they may be in the // middle of a SB word): if(ulCurCharset & HX_UNICODE_CHARSET || ulCurCharset & HX_DBCS_CHARSET) { UINT16 sCharWidthInPixels = 0; UINT16 sChar = '\0'; LONG32 lNumBytesOfChar = 1L; if(ulCurCharset & HX_UNICODE_CHARSET || (ulCurCharset & HX_DBCS_CHARSET && (UCHAR)(*pCurText)>= DBCS_MIN_LEAD_BYTE_VAL) ) { //Is a 2-byte character, so deal with it, // making sure there's a trail byte lNumBytesOfChar++; HX_ASSERT(tempLen>=lNumBytesOfChar); UCHAR tmp = *pCurText; sChar = (((UINT16)tmp)<<8 | (UCHAR)pCurText[1]); } else { sChar = (INT16)((UCHAR)(*pCurText)); }/* XXXEH-need while loop on each char until we find which character exceeds the window's right edge and only then end the text blob...: sCharWidthInPixels = GetCharacterWidth( sChar, m_pTextWindow->peekAtFontFaceStack(), m_pTextWindow->peekAtPointSizeStack(), //XXXEH- isBold and isItalicized need peek..() // functions written for them; assuming they are // TRUE only means wordwrap will happen a few // pixels early, if that: TRUE, TRUE, ulCurCharset); BOOL windowWidthExceeded = m_pTextWindow->getCurrentTextLineEndX() + sCharWidthInPixels > m_pTextWindow->getWidth(); XXXEH- ...but for now, just make each (2-byte)DBCS/UNICODE character be in its own TextContainer, although this can be less efficient:*/ //If we are going from DB char to DB char or from DB char // to SB char, or from SB char to DB char, or SB char is // a space, newline, or tab, or is a UNICODE character // with a non-zero first byte, or is a UNICODE space, tab, // or newline, then we can do a wordwrap // after this char, otherwise we should not: BOOL bNextCharExists = tempLen>lNumBytesOfChar; //Initialize to opposite of what cur character is: BOOL bNextCharIsTwoByte = (lNumBytesOfChar==1); if(bNextCharExists) { bNextCharIsTwoByte = (ulCurCharset & HX_UNICODE_CHARSET && ((UCHAR)(pCurText[lNumBytesOfChar])!=0)) || (ulCurCharset & HX_DBCS_CHARSET && (UCHAR)(pCurText[lNumBytesOfChar])>= DBCS_MIN_LEAD_BYTE_VAL); } BOOL bIsUNICODEcharThatCanBeWordwrapped = FALSE; if(ulCurCharset & HX_UNICODE_CHARSET) { if(*pCurText!=0) { bIsUNICODEcharThatCanBeWordwrapped = TRUE; } else { UCHAR ch = pCurText[1]; if(' '==ch || '\n'==ch || '\r'==ch || '\t'==ch) { bIsUNICODEcharThatCanBeWordwrapped = TRUE; } } } if((!(1==lNumBytesOfChar) || bNextCharIsTwoByte) || (1==lNumBytesOfChar && (' '==*pCurText || '\n'==*pCurText || '\r'==*pCurText || '\t'==*pCurText)) || bIsUNICODEcharThatCanBeWordwrapped ) { //End the text blob here so that wordwrap can occur // if this character extends off the right edge // of the window: theFollowingSpaceCharIndex = lNumBytesOfChar-1; savedChar = pCurText[theFollowingSpaceCharIndex+1]; pCurText[theFollowingSpaceCharIndex+1] = '\0'; } //If we're in a bunch of single-byte DBCS chars, then we // need to find the end of them (or the first space, tab, // newline therein), and allow for wordwrap there: else if(1==lNumBytesOfChar && tempLen) { _CHAR* pTmpText = pCurText; LONG32 lTmpTextLen = tempLen; BOOL bSpaceTabOrNewlineFound=FALSE; do { lNumBytesOfChar = (UCHAR)(*pTmpText)>= DBCS_MIN_LEAD_BYTE_VAL? 2:1; if(1==lNumBytesOfChar) { if(' '==*pTmpText || '\n'==*pTmpText || '\r'==*pTmpText || '\t'==*pTmpText) { bSpaceTabOrNewlineFound = TRUE; break; } } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -