📄 html.cpp
字号:
} } else if (str[i] == 0x00) { // End of string insertBlock = true; remainingStr = 0; } if (insertBlock) { if (*str) { if (textType == variable) {#ifdef EXEC_EXTENSIONS if(url || target || exec) flow->append(new HTMLLinkTextMaster(str,fp,painter,url,target,exec));#else if(url || target) flow->append(new HTMLLinkTextMaster(str,fp,painter,url,target));#endif else flow->append( new HTMLTextMaster( str, fp, painter ) ); } else {#ifdef EXEC_EXTENSIONS if(url || target || exec) flow->append(new HTMLLinkText(str,fp,painter,url,target,exec));#else if(url || target ) flow->append(new HTMLLinkText(str,fp,painter,url,target));#endif else flow->append( new HTMLText( str, fp, painter ) ); } } if (insertSpace) {#ifdef EXEC_EXTENSIONS if(url || target || exec) { HTMLLinkText *sp = new HTMLLinkText(" ",fp,painter,url,target,exec);#else if(url || target) { HTMLLinkText *sp = new HTMLLinkText(" ",fp,painter,url,target);#endif sp->setSeparator( true ); flow->append( sp ); } else { flow->append( new HTMLHSpace( fp, painter)); } } else if (insertNBSP) {#ifdef EXEC_EXTENSIONS if(url || target || exec) { HTMLLinkText *sp = new HTMLLinkText(" ",fp,painter,url,target,exec);#else if(url || target) { HTMLLinkText *sp = new HTMLLinkText(" ",fp,painter,url,target);#endif sp->setSeparator( false ); flow->append( sp ); } else { HTMLHSpace *sp = new HTMLHSpace( fp, painter); sp->setSeparator(false); flow->append( sp ); } } str = remainingStr; if ((str == 0) || (*str == 0x00)) return; // Finished i = 0; textType = unknown; insertBlock = false; insertSpace = false; insertNBSP = false; } else { i++; } }} const char* KHTMLWidget::parseBody( HTMLClueV *_clue, const char *_end[], bool toplevel ){ const char *str; // Before one can write any objects in the body he usually adds a FlowBox // to _clue. Then put all texts, images etc. in the FlowBox. // If f == 0, you have to create a new FlowBox, otherwise you can // use the one stored in f. Setting f to 0 means closing the FlowBox. while ( ht->hasMoreTokens() && parsing ) { str = ht->nextToken(); // ignore stuff inbetween <noframes> and </noframes> if // this has a htmlView if(bInNoframes) { str++; if(strncmp( str, "</noframes", 10 ) == 0) bInNoframes = false; else continue; } if ( *str == '\0' ) continue; if ( *str == ' ' && *(str+1) == '\0' ) { // if in* is set this text belongs in a form element if ( inOption || inTextArea ) formText += " "; else if ( inTitle ) title += " "; else if ( flow != 0) { insertText( " ", currentFont()); } } else if ( *str != TAG_ESCAPE ) { // if in* is set this text belongs in a form element if ( inOption || inTextArea ) { formText += str; } else if ( inTitle ) { title += str; } else { vspace_inserted = false; if (!flow) newFlow(_clue); if (charsetConverter){ debugM("Using charset converter..."); QList<KCharsetConversionResult> rl= charsetConverter->multipleConvert(str); debugM("OK\n"); KCharsetConversionResult *r=0; for(r=rl.first();r;r=rl.next()){ debugM("Getting result string..."); char *str1=r->copy(); debugM("Got: %s",str1); debugM("Getting current font..."); HTMLFont f=*currentFont(); debugM("OK\n"); debugM("Setting charset to %s...",(const char *)r->charset()); f.setCharset(r->charset()); debugM("OK\n"); debugM("Getting preloaded font..."); const HTMLFont *fp = pFontManager->getFont( f ); debugM("OK\n"); debugM("Adding string to flow..."); // Add this string to our own garbage collector if ((memPoolMax % 256) == 0) { memPool.resize(memPoolMax+256); } memPool[memPoolMax++] = str1; insertText(str1, fp); debugM("OK\n"); } } else{ insertText((char *)str, currentFont() ); // Override constness } } } else { str++; int i = 0; while ( _end[i] != 0 ) { if ( strncasecmp( str, _end[i], strlen( _end[i] ) ) == 0 ) { return str; } i++; } // The tag used for line break when we are in <pre>...</pre> if ( *str == '\n' ) { if (!flow) newFlow(_clue); // Add a hidden space to get the line-height right. flow->append(new HTMLHSpace( currentFont(), painter, true )); vspace_inserted = false; newFlow(_clue); // Explicitly make a new flow! } else if (*str == '&') { int l; const char *str1; if (!flow) newFlow(_clue); const HTMLFont *fp = currentFont(); // Handling entities char *buffer=new char[strlen(str)+2]; // buffer will never // have to be longer KCharsets *charsets= KApplication::getKApplication()->getCharsets(); const KCharsetConversionResult &r=charsets->convertTag(str,l); str1=r; if (str1 && l){ HTMLFont f=*fp; if (r.charset().ok()){ f.setCharset(r.charset()); fp = pFontManager->getFont( f ); } strcpy(buffer,str1); strcat(buffer,str+l); // Add this string to our own garbage collector if ((memPoolMax % 256) == 0) { memPool.resize(memPoolMax+256); } memPool[memPoolMax++] = buffer; insertText((char *)buffer, fp); // Override constness } else { insertText((char *)str, currentFont()); } } else { parseOneToken( _clue, str ); } } // perhaps we have the frame read complete. So skip the rest if ( bFramesComplete ) { stopParser(); return 0; } if ( toplevel ) { if ( parseCount <= 0 ) return 0; } parseCount--; } if ( !ht->hasMoreTokens() && toplevel && !writing ) stopParser(); return 0;}const char *KHTMLWidget::parseOneToken( HTMLClueV *_clue, const char *str ){ if ( *str == '<' ) { int indx; str++; if ( *str == '/' ) indx = *(str+1) - 'a'; else indx = *str - 'a'; if ( indx >= 0 && indx < 26 ) (this->*(parseFuncArray[indx]))( _clue, str ); } return 0;}// <a </a>// <address> </address>// <area </area>void KHTMLWidget::parseA( HTMLClueV *_clue, const char *str ){ if ( strncmp( str, "area", 4 ) == 0 ) { if ( mapList.isEmpty() ) return; stringTok->tokenize( str + 5, " >" ); QString href; QString coords; QString atarget = baseTarget.copy(); HTMLArea::Shape shape = HTMLArea::Rect; while ( stringTok->hasMoreTokens() ) { const char* p = stringTok->nextToken(); if ( strncasecmp( p, "shape=", 6 ) == 0 ) { if ( strncasecmp( p+6, "rect", 4 ) == 0 ) shape = HTMLArea::Rect; else if ( strncasecmp( p+6, "poly", 4 ) == 0 ) shape = HTMLArea::Poly; else if ( strncasecmp( p+6, "circle", 6 ) == 0 ) shape = HTMLArea::Circle; } else if ( strncasecmp( p, "href=", 5 ) == 0 ) { p += 5; if ( *p == '#' ) {// reference KURL u( actualURL ); u.setReference( p + 1 ); href = u.url(); } else { KURL u( baseURL, p ); href = u.url(); } } else if ( strncasecmp( p, "target=", 7 ) == 0 ) { atarget = p+7; } else if ( strncasecmp( p, "coords=", 7 ) == 0 ) { coords = p+7; } } if ( !coords.isEmpty() && !href.isEmpty() ) { HTMLArea *area = 0; switch ( shape ) { case HTMLArea::Rect: { int x1, y1, x2, y2; sscanf( coords, "%d,%d,%d,%d", &x1, &y1, &x2, &y2 ); QRect rect( x1, y1, x2-x1, y2-y1 ); area = new HTMLArea( rect, href, atarget ); debugM( "Area Rect %d, %d, %d, %d\n", x1, y1, x2, y2 ); } break; case HTMLArea::Circle: { int xc, yc, rc; sscanf( coords, "%d,%d,%d", &xc, &yc, &rc ); area = new HTMLArea( xc, yc, rc, href, atarget ); debugM( "Area Circle %d, %d, %d\n", xc, yc, rc ); } break; case HTMLArea::Poly: { debugM( "Area Poly " ); int count = 0, x, y; QPointArray parray; const char *ptr = coords; while ( ptr ) { x = atoi( ptr ); ptr = strchr( ptr, ',' ); if ( ptr ) { y = atoi( ++ptr ); parray.resize( count + 1 ); parray.setPoint( count, x, y ); debugM( "%d, %d ", x, y ); count++; ptr = strchr( ptr, ',' ); if ( ptr ) ptr++; } } debugM( "\n" ); if ( count > 2 ) area = new HTMLArea( parray, href, atarget ); } break; } if ( area ) mapList.getLast()->addArea( area ); } } else if ( strncmp( str, "address", 7) == 0 ) {// vspace_inserted = insertVSpace( _clue, vspace_inserted ); flow = 0; italic = TRUE; weight = QFont::Normal; selectFont(); pushBlock(ID_ADDRESS, 2, &KHTMLWidget::blockEndFont, true); } else if ( strncmp( str, "/address", 8) == 0 ) { popBlock( ID_ADDRESS, _clue); } else if ( strncmp( str, "a ", 2 ) == 0 ) { closeAnchor(); QString tmpurl;#ifdef EXEC_EXTENSIONS QString tmpexec;#endif target = 0; bool visited = false; const char *p; stringTok->tokenize( str + 2, " >" ); while ( ( p = stringTok->nextToken() ) != 0 ) { if ( strncasecmp( p, "href=", 5 ) == 0 ) { p += 5; KURL u; if ( *p == '#' ) {// reference u = KURL( actualURL ); u.setReference( p + 1 ); } else { u = KURL( baseURL, p ); } tmpurl = u.url(); visited = URLVisited( tmpurl ); } else if ( strncasecmp( p, "name=", 5 ) == 0 ) { if ( flow == 0 ) _clue->append( new HTMLAnchor( p+5 ) ); else flow->append( new HTMLAnchor( p+5 ) ); } else if ( strncasecmp( p, "target=", 7 ) == 0 ) { target = new char [ strlen( p+7 ) + 1 ]; strcpy( target, p+7 ); parsedTargets.append( target ); }#ifdef EXEC_EXTENSIONS else if(strncasecmp(p,"exec=",5) == 0) { tmpexec = p + 5; }#endif } if ( !target && !baseTarget.isEmpty() ) { target = new char [ baseTarget.length()+1 ]; strcpy( target, baseTarget ); parsedTargets.append( target ); }#ifdef EXEC_EXTENSIONS if(!tmpexec.isEmpty()) { vspace_inserted = false; colorStack.push(new QColor(settings->eLinkColor)); if(settings->underlineLinks) underline = true; selectFont(); exec = new char [tmpexec.length() + 1]; strcpy(exec,tmpexec.data()); parsedExecs.append(exec); }#endif if ( !tmpurl.isEmpty() ) { vspace_inserted = false; if ( visited ) colorStack.push( new QColor( settings->vLinkColor ) ); else colorStack.push( new QColor( settings->linkColor ) ); if ( settings->underlineLinks ) underline = true; selectFont(); url = new char [ tmpurl.length() + 1 ]; strcpy( url, tmpurl.data() ); parsedURLs.append( url ); } } else if ( strncmp( str, "/a", 2 ) == 0 ) { closeAnchor(); }}// <b> </b>// <base// <basefont unimplemented// <big> </big>// <blockquote> </blockquote>// <body// <brvoid KHTMLWidget::parseB( HTMLClueV *_clue, const char *str ){ if ( strncmp( str, "basefont", 8 ) == 0 ) { } else if ( strncmp(str, "base", 4 ) == 0 ) { stringTok->tokenize( str + 5, " >" ); while ( stringTok->hasMoreTokens() ) { const char* token = stringTok->nextToken(); if ( strncasecmp( token, "target=", 7 ) == 0 ) { baseTarget = token+7; } else if ( strncasecmp( token, "href=", 5 ) == 0 ) { setBaseURL( token + 5); } } } else if ( strncmp(str, "big", 3 ) == 0 ) {// CRH selectFont( +2 ); selectFont( +1 ); pushBlock(ID_BIG, 1, &KHTMLWidget::blockEndFont); } else if ( strncmp(str, "/big", 4 ) == 0 ) { popBlock( ID_BIG, _clue); } else if ( strncmp(str, "blockquote", 10 ) == 0 ) { pushBlock(ID_BLOCKQUOTE, 2, &KHTMLWidget::blockEndIndent, indent); indent += INDENT_SIZE; flow = 0; } els
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -