jcs
/wikipedia
/amendments
/21
browser: Draw lines under H1/H2 with em-dashes
Also calculate how wide the TE is so we can write the proper number
of dashes rather than guessing.
jcs made amendment 21 over 2 years ago
--- browser.c Fri Sep 2 14:03:49 2022
+++ browser.c Mon Sep 5 00:38:47 2022
@@ -124,8 +124,8 @@ browser_init(void)
/* main window */
width = screenBits.bounds.right - screenBits.bounds.left - PADDING;
- if (width > 620)
- width = 620;
+ if (width > 500)
+ width = 500;
height = screenBits.bounds.bottom - screenBits.bounds.top -
PADDING - (GetMBarHeight() * 2);
if (height > 340)
@@ -263,20 +263,26 @@ browser_update(struct focusable *focusable, EventRecor
case updateEvt:
FillRect(&browser->win->portRect, fill_pattern);
+ HLock(browser->input_te);
r = (*(browser->input_te))->viewRect;
+ HUnlock(browser->input_te);
FillRect(&r, white);
TEUpdate(&r, browser->input_te);
InsetRect(&r, -1, -1);
FrameRect(&r);
+ HLock(browser->te);
r = (*(browser->te))->viewRect;
+ HUnlock(browser->te);
FillRect(&r, white);
TEUpdate(&r, browser->te);
InsetRect(&r, -1, -1);
FrameRect(&r);
if (browser->search_results != NULL) {
+ HLock(browser->search_results);
r = (*(browser->search_results))->rView;
+ HUnlock(browser->search_results);
InsetRect(&r, -1, -1);
FillRect(&r, white);
FrameRect(&r);
@@ -305,7 +311,9 @@ browser_mouse_down(struct focusable *focusable, EventR
p = event->where;
GlobalToLocal(&p);
+ HLock(browser->input_te);
r = (*(browser->input_te))->viewRect;
+ HUnlock(browser->input_te);
if (PtInRect(p, &r)) {
TEClick(p, ((event->modifiers & shiftKey) != 0), browser->input_te);
browser_update_menu(browser);
@@ -313,7 +321,9 @@ browser_mouse_down(struct focusable *focusable, EventR
}
if (browser->search_results != NULL) {
+ HLock(browser->search_results);
r = (*(browser->search_results))->rView;
+ HUnlock(browser->search_results);
r.right += SCROLLBAR_WIDTH;
if (PtInRect(p, &r)) {
LClick(p, event->modifiers, browser->search_results);
@@ -322,7 +332,9 @@ browser_mouse_down(struct focusable *focusable, EventR
len = sizeof(str);
LGetCell(&str, &len, selected, browser->search_results);
TESetText(str, len, browser->input_te);
+ HLock(browser->input_te);
InvalRect(&(*(browser->input_te))->viewRect);
+ HUnlock(browser->input_te);
browser_hide_search_results(browser);
browser->state = BROWSER_STATE_ARTICLE_GET;
}
@@ -331,7 +343,9 @@ browser_mouse_down(struct focusable *focusable, EventR
}
}
+ HLock(browser->te);
r = (*(browser->te))->viewRect;
+ HUnlock(browser->te);
if (PtInRect(p, &r)) {
TEClick(p, ((event->modifiers & shiftKey) != 0), browser->te);
browser_update_menu(browser);
@@ -535,9 +549,19 @@ browser_print(struct browser *browser, const char *str
scrp_ele->scrpFace |= underline;
if (style & STYLE_H1) {
scrp_ele->scrpSize += 8;
- scrp_ele->scrpHeight += 8;
+ scrp_ele->scrpHeight += 10;
scrp_ele->scrpAscent += 8;
+ } else if (style & STYLE_H2) {
+ scrp_ele->scrpSize += 4;
+ scrp_ele->scrpHeight += 6;
+ scrp_ele->scrpAscent += 4;
+ } else if (style & STYLE_H3) {
+ scrp_ele->scrpSize += 2;
+ scrp_ele->scrpHeight += 4;
+ scrp_ele->scrpAscent += 2;
}
+
+
if (style & STYLE_LINK) {
/* remove link destinations for now */
@@ -611,11 +635,8 @@ no_overflow:
last_style = style;
- if (style & STYLE_H1) {
- browser_print(browser,
- "\r------------------------------------------------------------\r",
- 62, STYLE_BOLD);
- }
+ if (style & (STYLE_H1 | STYLE_H2))
+ browser_draw_line(browser);
return len;
}
@@ -624,4 +645,35 @@ void
browser_clear(struct browser *browser)
{
+}
+
+void
+browser_draw_line(struct browser *browser)
+{
+ char line[255];
+ size_t n, lsize;
+ short curfont, cursize, cwidth;
+ unsigned char emd = '—'; /* em-dash 0xd1 */
+
+ curfont = thePort->txFont;
+ cursize = thePort->txSize;
+ TextFont(BROWSER_FONT);
+ TextSize(BROWSER_FONT_SIZE);
+ cwidth = CharWidth(emd);
+ TextFont(curfont);
+ TextSize(cursize);
+
+ HLock(browser->te);
+ lsize = (*(browser->te))->viewRect.right - (*(browser->te))->viewRect.left;
+ HUnlock(browser->te);
+
+ lsize /= cwidth;
+ if (lsize > sizeof(line))
+ lsize = sizeof(line);
+
+ line[0] = '\r';
+ for (n = 1; n < lsize - 1; n++)
+ line[n] = emd;
+ line[lsize - 1] = '\r';
+ browser_print(browser, line, lsize, STYLE_BOLD);
}
--- browser.h Fri Sep 2 13:57:10 2022
+++ browser.h Mon Sep 5 00:19:59 2022
@@ -51,5 +51,6 @@ struct browser *browser_init(void);
size_t browser_print(struct browser *browser, const char *str, size_t len,
unsigned short style);
void browser_clear(struct browser *browser);
+void browser_draw_line(struct browser *browser);
#endif