@@ -950,9 +950,15 @@ void MCBlock::split(findex_t p_index)
950950void MCBlock::drawstring (MCDC *dc, coord_t x, coord_t p_cell_left, coord_t p_cell_right, int2 y, findex_t start, findex_t length, Boolean image, uint32_t style)
951951{
952952 // MW-2012-02-16: [[ FontRefs ]] Fetch the font metrics we need to draw.
953- int32_t t_ascent, t_descent;
953+ coord_t t_ascent, t_descent, t_leading, t_xheight ;
954954 t_ascent = MCFontGetAscent (m_font);
955955 t_descent = MCFontGetDescent (m_font);
956+ t_leading = MCFontGetLeading (m_font);
957+ t_xheight = MCFontGetXHeight (m_font);
958+
959+ // Width for strike-through/underline lines. Factor is arbitrary...
960+ coord_t t_strikewidth;
961+ t_strikewidth = ceilf (MCFontGetAscent (m_font)/16 );
956962
957963 // MW-2012-01-25: [[ ParaStyles ]] Fetch the vGrid setting from the owning paragraph.
958964 if (parent -> getvgrid ())
@@ -1011,9 +1017,17 @@ void MCBlock::drawstring(MCDC *dc, coord_t x, coord_t p_cell_left, coord_t p_cel
10111017 if (t_next_index - t_index > 0 )
10121018 {
10131019 if ((style & FA_UNDERLINE ) != 0 )
1014- dc -> drawline (x, y + 1 , x + t_width, y + 1 );
1020+ {
1021+ MCRectangle t_underlinerect;
1022+ t_underlinerect = MCU_make_rect (x, y + t_strikewidth, t_width, t_strikewidth);
1023+ dc -> fillrect (t_underlinerect);
1024+ }
10151025 if ((style & FA_STRIKEOUT ) != 0 )
1016- dc -> drawline (x, y - (t_ascent >> 1 ), x + t_width, y - (t_ascent >> 1 ));
1026+ {
1027+ MCRectangle t_strikerect;
1028+ t_strikerect = MCU_make_rect (x, y - (t_xheight / 2 ) - (t_strikewidth / 2 ), t_width, t_strikewidth);
1029+ dc -> fillrect (t_strikerect);
1030+ }
10171031 if ((style & FA_BOX ) != 0 )
10181032 {
10191033 // MW-2012-09-04: [[ Bug 9759 ]] Adjust any pattern origin to scroll with text.
@@ -1111,9 +1125,17 @@ void MCBlock::drawstring(MCDC *dc, coord_t x, coord_t p_cell_left, coord_t p_cel
11111125
11121126 // Apply strike/underline.
11131127 if ((style & FA_UNDERLINE ) != 0 )
1114- dc -> drawline (t_line_x, y + 1 , t_line_x + t_line_width, y + 1 );
1128+ {
1129+ MCRectangle t_underlinerect;
1130+ t_underlinerect = MCU_make_rect (t_line_x, y + t_strikewidth, t_line_width, t_strikewidth);
1131+ dc -> fillrect (t_underlinerect);
1132+ }
11151133 if ((style & FA_STRIKEOUT ) != 0 )
1116- dc -> drawline (t_line_x, y - (t_ascent >> 1 ), t_line_x + t_line_width, y - (t_ascent >> 1 ));
1134+ {
1135+ MCRectangle t_strikerect;
1136+ t_strikerect = MCU_make_rect (t_line_x, y - (t_xheight / 2 ) - (t_strikewidth / 2 ), t_line_width, t_strikewidth);
1137+ dc -> fillrect (t_strikerect);
1138+ }
11171139 }
11181140}
11191141
@@ -1177,8 +1199,7 @@ void MCBlock::draw(MCDC *dc, coord_t x, coord_t lx, coord_t cx, int2 y, findex_t
11771199 if (flags & F_HAS_BACK_COLOR )
11781200 dc->setbackground (*atts->backcolor );
11791201
1180- if (t_foreground_color != NULL )
1181- dc -> setforeground (*t_foreground_color);
1202+ setcolorfornormaltext (dc, t_foreground_color);
11821203
11831204 uint32_t t_style;
11841205 t_style = 0 ;
@@ -1292,11 +1313,13 @@ void MCBlock::draw(MCDC *dc, coord_t x, coord_t lx, coord_t cx, int2 y, findex_t
12921313 f->getforecolor (DI_HILITE , False, True, hc, t_pattern, x, y, dc, f);
12931314 if (hc.pixel == fc.pixel )
12941315 f->setforeground (dc, DI_BACK , False, True);
1316+ else
1317+ setcolorforselectedtext (dc, nil);
12951318 }
12961319 else
1297- f-> setforeground (dc, DI_BACK , False, True );
1320+ setcolorforselectedtext (dc, t_foreground_color );
12981321 }
1299-
1322+
13001323 // Draw the selected text.
13011324 // SN-2014-08-13: [[ Bug 13016 ]] Added a parameter for the left of the cell
13021325 drawstring (dc, x, lx, cx, y, m_index, m_size, (flags & F_HAS_BACK_COLOR ) != 0 , t_style);
@@ -1888,7 +1911,7 @@ uint2 MCBlock::getascent(void)
18881911 if (flags & F_HAS_IMAGE && atts->image != NULL )
18891912 return MCU_max (0 , atts->image ->getrect ().height - shift + 2 );
18901913 else
1891- return MCU_max (0 , heightfromsize (MCFontGetAscent (m_font)) - MCFontGetDescent (m_font) - shift);
1914+ return MCU_max (0 , heightfromsize (ceilf ( MCFontGetAscent (m_font))) - uint2 ( ceilf ( MCFontGetDescent (m_font)) ) - shift);
18921915}
18931916
18941917uint2 MCBlock::getdescent (void )
@@ -1897,7 +1920,35 @@ uint2 MCBlock::getdescent(void)
18971920 if (flags & F_HAS_IMAGE && atts->image != NULL )
18981921 return MCU_max (0 , shift);
18991922 else
1900- return MCU_max (0 , MCFontGetDescent (m_font) + shift);
1923+ return MCU_max (0 , uint2 (ceilf (MCFontGetDescent (m_font))) + shift);
1924+ }
1925+
1926+ coord_t MCBlock::GetAscent () const
1927+ {
1928+ int2 shift = flags & F_HAS_SHIFT ? atts->shift : 0 ;
1929+ // MW-2007-07-05: [[ Bug 1943 ]] - Images do not have correct ascent height *MIGHT NEED REVERSION*
1930+ if (flags & F_HAS_IMAGE && atts->image != NULL )
1931+ return MCU_max (0 , atts->image ->getrect ().height - shift + 2 );
1932+ else
1933+ return MCU_max (0 .0f , MCFontGetAscent (m_font) - shift);
1934+ }
1935+
1936+ coord_t MCBlock::GetDescent () const
1937+ {
1938+ int2 shift = flags & F_HAS_SHIFT ? atts->shift : 0 ;
1939+ if (flags & F_HAS_IMAGE && atts->image != NULL )
1940+ return MCU_max (0 , shift);
1941+ else
1942+ return MCU_max (0 .0f , MCFontGetDescent (m_font) + shift);
1943+ }
1944+
1945+ coord_t MCBlock::GetLeading () const
1946+ {
1947+ int2 shift = flags & F_HAS_SHIFT ? atts->shift : 0 ;
1948+ if (flags & F_HAS_IMAGE && atts->image != NULL )
1949+ return GetAscent ()+GetDescent ();
1950+ else
1951+ return MCFontGetLeading (m_font);
19011952}
19021953
19031954void MCBlock::freeatts ()
@@ -2400,3 +2451,36 @@ MCBlock *MCBlock::GetPrevBlockVisualOrder()
24002451
24012452 return nil;
24022453}
2454+
2455+ void MCBlock::setcolorfornormaltext (MCDC * dc, MCColor* p_color)
2456+ {
2457+ MCField* f = parent->getparent ();
2458+
2459+ if (p_color != nil)
2460+ dc->setforeground (*p_color);
2461+ else if (flags & F_HAS_COLOR )
2462+ dc->setforeground (*atts -> color);
2463+ else
2464+ f->setforeground (dc, DI_PSEUDO_TEXT_COLOR , False, True);
2465+ }
2466+
2467+ void MCBlock::setcolorforhilite (MCDC * dc)
2468+ {
2469+ MCField* f = parent->getparent ();
2470+
2471+ f->setforeground (dc, DI_PSEUDO_TEXT_BACKGROUND_SEL , False, True);
2472+ }
2473+
2474+ void MCBlock::setcolorforselectedtext (MCDC * dc, MCColor* p_color)
2475+ {
2476+ MCField* f = parent->getparent ();
2477+
2478+ if (p_color != nil)
2479+ dc->setforeground (*p_color);
2480+ else if (flags & F_HAS_COLOR )
2481+ dc->setforeground (*atts -> color);
2482+ else if (!IsMacLF ()) // TODO: if platform reverses selected text
2483+ f->setforeground (dc, DI_PSEUDO_TEXT_COLOR_SEL_BACK , False, True, true );
2484+ else
2485+ f->setforeground (dc, DI_PSEUDO_TEXT_COLOR_SEL_FORE , False, True, true );
2486+ }
0 commit comments