📄 gridtext.c
字号:
/* Terminate finished line for printing*/ previous->data[previous->size] = 0;/* Align left, right or center*/ spare = (int) (HTScreenWidth - style->rightIndent + style->leftIndent - previous->size); /* @@ first line indent */ switch (style->alignment) { case HT_CENTER : previous->offset = previous->offset + indent + spare/2; break; case HT_RIGHT : previous->offset = previous->offset + indent + spare; break; case HT_LEFT : case HT_JUSTIFY : /* Not implemented */ default: previous->offset = previous->offset + indent; break; } /* switch */ text->chars = text->chars + previous->size + 1; /* 1 for the line */ text->in_line_1 = NO; /* unless caller sets it otherwise */ /* If displaying as we go, output it:*/ if (text->display_on_the_fly) { if (text->display_on_the_fly == DISPLAY_LINES) { /* First line */ if (previous->size == 0) { text->top_of_screen++; /* Scroll white space off top */ return; } if (HTAnchor_title(text->node_anchor)) { /* Title exists */ display_title(text); text->display_on_the_fly--; } } display_line(text, previous); text->display_on_the_fly--; /* Loop to top of next page? */ if (!text->display_on_the_fly && text->all_pages) { PUTS("\f\n"); /* Form feed on its own line a la rfc1111 */ text->display_on_the_fly = DISPLAY_LINES; } }} /* split_line *//* Allow vertical blank space** --------------------------*/PRIVATE void blank_lines (HText * text, int newlines){ if (text->last_line->size == 0) { /* No text on current line */ HTLine * line = text->last_line->prev; while ((line!=text->last_line) && (line->size == 0)) { if (newlines==0) break; newlines--; /* Don't bother: already blank */ line = line->prev; } } else { newlines++; /* Need also to finish this line */ } for(;newlines;newlines--) { new_line(text); } text->in_line_1 = YES;}/* New paragraph in current style** ------------------------------** See also: setStyle.*/PUBLIC void HText_appendParagraph (HText * text){ int after = (int) text->style->spaceAfter; int before = (int) text->style->spaceBefore; blank_lines(text, after>before ? after : before);}/* Set Style** ---------**** Does not filter unnecessary style changes.*/PUBLIC void HText_setStyle (HText * text, HTStyle * style){ int after, before; if (!style) return; /* Safety */ after = (int) text->style->spaceAfter; before = (int) style->spaceBefore; HTTRACE(SGML_TRACE, "Rendering... Change to style %s\n" _ style->name); blank_lines (text, after>before ? after : before); text->style = style;}/* Append a character to the text object** -------------------------------------*/PUBLIC void HText_appendCharacter (HText * text, char ch){ HTLine * line = text->last_line; HTStyle * style = text->style; int indent = (int)(text->in_line_1 ? style->indent1st : style->leftIndent); /* New Line*/ if (ch == '\n') { new_line(text); text->in_line_1 = YES; /* First line of new paragraph */ return; }/* Tabs*/ if (ch == '\t') { HTTabStop * tab; int target; /* Where to tab to */ int here = line->size + line->offset +indent; if (style->tabs) { /* Use tab table */ for (tab = style->tabs; tab->position <= here; tab++) if (!tab->position) { new_line(text); return; } target = (int) tab->position; } else if (text->in_line_1) { /* Use 2nd indent */ if (here >= style->leftIndent) { new_line(text); /* wrap */ return; } else { target = (int) style->leftIndent; } } else { /* Default tabs align with left indent mod 8 */#ifdef DEFAULT_TABS_8 target = ((line->offset + line->size + 8) & (-8)) + style->leftIndent;#else new_line(text); return;#endif } if (target > HTScreenWidth - style->rightIndent) { new_line(text); return; } else { text->permissible_split = line->size; /* Can split here */ if (line->size == 0) line->offset = line->offset + target - here; else for(; here<target; here++) { line->data[line->size++] = ' '; /* Put character into line */ } return; } /*NOTREACHED*/ } /* if tab */ if (ch==' ') { text->permissible_split = line->size; /* Can split here */ }/* Check for end of line*/ if (indent + line->offset + line->size + style->rightIndent >= HTScreenWidth) { if (style->wordWrap) { if(text->permissible_split > line->size) /* HENRIK 21/02-94 */ text->permissible_split = line->size; split_line(text, text->permissible_split); if (ch==' ') return; /* Ignore space causing split */ } else new_line(text); }/* Insert normal characters*/ if (ch == HT_NON_BREAK_SPACE) { ch = ' '; } { HTLine * line = text->last_line; /* May have changed */ HTFont font = style->font; line->data[line->size++] = /* Put character into line */ font & HT_CAPITALS ? TOUPPER(ch) : ch; if (font & HT_DOUBLE) /* Do again if doubled */ HText_appendCharacter(text, HT_NON_BREAK_SPACE); /* NOT a permissible split */ }}PUBLIC void HText_appendText (HText * text, const char * str){ const char * p; for(p=str; *p; p++) { HText_appendCharacter(text, *p); }}PUBLIC void HText_endAppend (HText * text){ new_line(text); if (text->display_on_the_fly) { /* Not finished? */ fill_screen(text, text->display_on_the_fly); /* Finish it */ text->display_on_the_fly = 0; text->next_line = text->last_line; /* Bug fix after EvA 920117 */ text->stale = NO; }}/* Anchor handling** ---------------*//* Start an anchor field*/PUBLIC void LMHText_beginAnchor (HText * text, int elem_num, int attr_num, HTChildAnchor * anc, const BOOL *present, const char **value){ TextAnchor * a; /* this is because it's called as link callback */ if (elem_num != HTML_A) return; if ((a = (TextAnchor *) HT_MALLOC(sizeof(*a))) == NULL) HT_OUTOFMEM("HText_beginAnchor"); a->start = text->chars + text->last_line->size; a->extent = 0; if (text->last_anchor) { text->last_anchor->next = a; } else { text->first_anchor = a; } a->next = 0; a->anchor = anc; text->last_anchor = a; text->current_anchor = a; if (HTAnchor_followMainLink((HTAnchor*)anc)) { a->number = ++(text->last_anchor_number); } else { a->number = 0; }}PUBLIC void LMHText_endAnchor (HText * text){ TextAnchor * a = text->current_anchor; char marker[100]; if (!a) /* </A> without <A> */ return; if (a->number && display_anchors) { /* If it goes somewhere */ sprintf(marker, end_reference, a->number); HText_appendText(text, marker); } a->extent = text->chars + text->last_line->size - a->start; text->current_anchor = 0;}/* LMHText_addText() satisfies HText callback requirement. */PUBLIC void LMHText_addText (HText * text, const char * str, int length){ const char * p; int i; for (i=0,p=str; i<length; ++i,++p) { HText_appendCharacter(text, *p); }}/* IMAGES*/PUBLIC void HText_appendImage ( HText * text, HTChildAnchor * anc, const char * alt, const char * alignment, BOOL isMap){ HText_appendText(text, alt? alt : "[IMAGE]");}PUBLIC void HText_appendObject (HText * text, int element_number, const BOOL * present, const char ** value){}PUBLIC void HText_appendLink (HText * text, HTChildAnchor * anchor, const BOOL * present, const char ** value){}/* Return the anchor associated with this node*/PUBLIC HTParentAnchor * HText_nodeAnchor (HText * text){ return text->node_anchor;}/* GridText specials** =================*//* Return the anchor with index N**** The index corresponds to the number we print in the anchor.*/PUBLIC HTChildAnchor * HText_childNumber (HText * text, int number){ TextAnchor * a; for (a = text->first_anchor; a; a = a->next) { if (a->number == number) return a->anchor; } return (HTChildAnchor *)0; /* Fail */}PUBLIC void HText_setStale (HText * text){ if (text) text->stale = YES;}PUBLIC void HText_refresh (HText * text){ if (text && text->stale) display_page(text, text->top_of_screen);}PUBLIC int HText_sourceAnchors (HText * text){ return (text ? text->last_anchor_number : -1);}PUBLIC BOOL HText_canScrollUp (HText * text){ return (text && text->top_of_screen != 0);}PUBLIC BOOL HText_canScrollDown (HText * text){ return (text && (text->top_of_screen + DISPLAY_LINES - (text->title ? TITLE_LINES : 0)) < text->lines);}/* Scroll actions*/PUBLIC void HText_scrollTop (HText * text){ display_page(text, 0);}PUBLIC void HText_scrollDown (HText * text){ display_page(text, text->top_of_screen + DISPLAY_LINES -1);}PUBLIC void HText_scrollUp (HText * text){ display_page(text, text->top_of_screen - DISPLAY_LINES +1);}PUBLIC void HText_scrollBottom (HText * text){ display_page(text, text->lines - DISPLAY_LINES +1);}/* Browsing functions** ==================*//* Bring to front and highlight it*/PRIVATE int line_for_char (HText * text, int char_num){ int line_number =0; int characters = 0; HTLine * line = text->last_line->next; for(;;) { if (line == text->last_line) return 0; /* Invalid */ characters = characters + line->size + 1; if (characters > char_num) return line_number; line_number ++; line = line->next; }}PUBLIC BOOL HText_select (HText * text){ if (text) { HTMainText = text; HTMainAnchor = text->node_anchor; display_page(text, text->top_of_screen); return YES; } HTTRACE(SGML_TRACE, "Rendering... Nothing to select!\n"); return NO;}PUBLIC BOOL HText_selectAnchor (HText * text, HTChildAnchor * anchor){ TextAnchor * a; for(a=text->first_anchor; a; a=a->next) { if (a->anchor == anchor) break; } if (!a) { HTTRACE(SGML_TRACE, "Rendering... No such anchor in this text!\n"); return NO; } if (text != HTMainText) { /* Comment out by ??? */ HTMainText = text; /* Put back in by tbl 921208 */ HTMainAnchor = text->node_anchor; } { int l = line_for_char(text, a->start); HTTRACE(SGML_TRACE, "Rendering... Selecting anchor [%d] at char %d, line %d\n" _ a->number _ a->start _ l); if ( !text->stale && (l >= text->top_of_screen) && ( l < text->top_of_screen + DISPLAY_LINES-1)) return YES; display_page(text, l - (DISPLAY_LINES/3)); /* Scroll to it */ } return YES;} /* Editing functions - NOT IMPLEMENTED** =================**** These are called from the application. There are many more functions** not included here from the orginal text object.*//* Style handling:*//* Apply this style to the selection*/PUBLIC void HText_applyStyle (HText * me, HTStyle * style){ }/* Update all text with changed style.*/PUBLIC void HText_updateStyle (HText * me, HTStyle * style){ }/* Return style of selection*/PUBLIC HTStyle * HText_selectionStyle ( HText * me, HTStyleSheet * sheet){ return 0;}/* Paste in styled text*/PUBLIC void HText_replaceSel ( HText * me, const char * aString, HTStyle * aStyle){}/* Apply this style to the selection and all similarly formatted text** (style recovery only)*/PUBLIC void HTextApplyToSimilar (HText * me, HTStyle * style){ } /* Select the first unstyled run.** (style recovery only)*/PUBLIC void HTextSelectUnstyled (HText * me, HTStyleSheet * sheet){ }/* Anchor handling:*/PUBLIC void HText_unlinkSelection (HText * me){ }PUBLIC HTAnchor * HText_referenceSelected (HText * me){ return 0; }#ifdef CURSESPUBLIC int HText_getTopOfScreen (HText * text){ return text->top_of_screen;}PUBLIC int HText_getLines (HText * text){ return text->lines;}#endifPUBLIC HTAnchor * HText_linkSelTo (HText * me, HTAnchor * anchor){ return 0;}/* HTML callback functions*/PUBLIC void LMHText_beginElement (HText * text, int elem_num, const BOOL * present, const char ** value){ return;}PUBLIC void LMHText_endElement (HText * text, int elem_num){ switch (elem_num) { case HTML_A: LMHText_endAnchor (text); break; default: break; } return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -