void _wtextout( /*************/ char *text, float x, float y, int hor_align, int ver_align, void *wfont ) { WORD horiz_flags; WORD vert_flags; WPI_FONT old_font; int dx; int dy; WPI_TEXTMETRIC font_info; int len; int bk_mode; int px1; int py1; int px2; int py2; int width; int height; WPI_FONT font; font = (WPI_FONT) wfont; bk_mode = _wpi_getbackmode( Win_dc ); _wpi_setbackmode( Win_dc, TRANSPARENT ); len = strlen( text ); convert_pt( x, y, &dx, &dy ); old_font = _wpi_selectfont( Win_dc, font ); if( Text_path == TEXT_VERTICAL ) { _wpi_gettextmetrics( Win_dc, &font_info ); width = _wpi_metricmaxcharwidth( font_info ); height = len * _wpi_metricheight( font_info ); } else { _wpi_gettextextent( Win_dc, text, len, &width, &height ); } px1 = px2 = dx; py1 = py2 = dy; switch( hor_align ) { case TEXT_H_LEFT: horiz_flags = TA_LEFT; px2 += width; break; case TEXT_H_CENTER: horiz_flags = TA_CENTER; px1 -= width / 2; px2 += width / 2; break; case TEXT_H_RIGHT: horiz_flags = TA_RIGHT; px2 -= width; break; } switch( ver_align ) { case TEXT_V_TOP: py2 += height * WPI_VERT_MULT; break; case TEXT_V_CENTER: py1 -= height / 2 * WPI_VERT_MULT; py2 += height / 2 * WPI_VERT_MULT; break; case TEXT_V_BOTTOM: py2 -= height * WPI_VERT_MULT; break; } rgn_rectangle( px1, py1, px2, py2 ); if( Text_path == TEXT_HORIZONTAL ) { /* normal right path */ switch( ver_align ) { case TEXT_V_TOP: #ifdef PLAT_OS2 /* OS/2 has problems with TA_LEFT && TA_TOP aligned text */ /* This is a messy solution until we actually figure out */ /* what the problem is. */ vert_flags = TA_BOTTOM; _wpi_gettextmetrics( Win_dc, &font_info ); dy += _wpi_metricheight( font_info ) * WPI_VERT_MULT; #else vert_flags = TA_TOP; #endif break; case TEXT_V_CENTER: #ifdef PLAT_OS2 vert_flags = TA_HALF; #else /* OS/2 has a much cleverer way of doing this */ /* but Windows apparently doesn't */ vert_flags = TA_TOP; _wpi_gettextmetrics( Win_dc, &font_info ); dy -= _wpi_metricheight( font_info ) / 2 * WPI_VERT_MULT; #endif break; case TEXT_V_BOTTOM: vert_flags = TA_BOTTOM; break; } _wpi_settextalign( Win_dc, horiz_flags, vert_flags ); _wpi_textout( Win_dc, dx, dy, text, len ); } else { /* must display text vertically... do it by hand */ vert_flags = TA_TOP; _wpi_settextalign( Win_dc, horiz_flags, vert_flags ); switch( ver_align ) { case TEXT_V_BOTTOM: dy -= _wpi_metricheight( font_info ) * len * WPI_VERT_MULT; break; case TEXT_V_CENTER: dy -= (_wpi_metricheight( font_info ) * len) / 2 * WPI_VERT_MULT; break; } _wpi_settextalign( Win_dc, horiz_flags, vert_flags ); for( ; len > 0; --len, dy += _wpi_metricheight( font_info ) * WPI_VERT_MULT, ++text ) { _wpi_textout( Win_dc, dx, dy, text, 1 ); } } _wpi_getoldfont( Win_dc, old_font ); _wpi_setbackmode( Win_dc, bk_mode ); }
void GUIDrawTextBitmapRGB( gui_window *wnd, const char *text, size_t length, int height, gui_coord *pos, WPI_COLOUR fore, WPI_COLOUR back, gui_ord extentx, bool draw_extent, int bitmap ) { int nDrawX, nDrawY; UINT lenx; HBRUSH brush; HBRUSH old_brush; HPEN pen; HPEN old_pen; int old_rop; size_t num_chars; WPI_RECT rect; gui_coord indent; int hscroll_pos; gui_coord extent; WPI_COLOUR colour; GUI_RECTDIM left, top, right, bottom; GUI_RECTDIM paint_left, paint_top, paint_right, paint_bottom; WPI_RECT paint_rect; WPI_RECT draw_rect; //draw_cache dcache; if( ( wnd->hdc == NULLHANDLE ) || ( wnd->ps == NULL ) || ( ( text == NULL ) && ( bitmap == 0 ) ) || ( ( bitmap != 0 ) && ( height == 0 ) ) ) { return; } old_rop = 0; old_brush = (HBRUSH)NULL; brush = (HBRUSH)NULL; old_pen = (HPEN)NULL; pen = (HPEN)NULL; GUIGetMetrics( wnd ); if( !bitmap ) { height = AVGYCHAR(GUItm); } rect = wnd->hwnd_client; _wpi_getrectvalues( rect, &left, &top, &right, &bottom); _wpi_getpaintrect( wnd->ps, &paint_rect ); _wpi_getwrectvalues( paint_rect, &paint_left, &paint_top, &paint_right, &paint_bottom ); top = paint_top / height * height; bottom = ( paint_bottom + height - 1) / height * height; if( GUI_DO_HSCROLL( wnd ) ) { hscroll_pos = GUIGetScrollPos( wnd, SB_HORZ ); } else { hscroll_pos = 0; } if( bitmap == 0 ) { num_chars = strlen( text ); if( num_chars > length ) { num_chars = length; } } indent.x = pos->x; indent.y = pos->y; GUIScaleToScreenR( &indent ); nDrawY = indent.y; if( GUI_DO_VSCROLL( wnd ) ) { nDrawY -= GUIGetScrollPos( wnd, SB_VERT ); } nDrawX = left; nDrawX += ( indent.x - hscroll_pos ); if( bitmap > 0 ) { lenx = length ; } else { lenx = GUIGetTextExtentX( wnd, text, num_chars ); } if( draw_extent ) { /* blanks out some portion of rest of the line */ if( extentx != GUI_NO_COLUMN ) { extent.x = extentx; GUIScaleToScreen( &extent ); right = nDrawX + extent.x; } } else { right = nDrawX + lenx; } nDrawY = _wpi_cvth_y_size( nDrawY, _wpi_getheightrect(wnd->hwnd_client), height ); _wpi_setrectvalues( &draw_rect, nDrawX, nDrawY, right, nDrawY+height ); if( GUIIsRectInUpdateRect( wnd, &draw_rect ) ) { colour = _wpi_getnearestcolor( wnd->hdc, back ); brush = _wpi_createsolidbrush( colour ); pen = _wpi_createpen( PS_SOLID, 1, colour ); if( pen == NULLHANDLE ) { GUIError(LIT( Pen_Failed )); } old_brush = _wpi_selectbrush( wnd->hdc, brush ); old_pen = _wpi_selectpen( wnd->hdc, pen ); #ifdef __OS2_PM__ _wpi_rectangle( wnd->hdc, nDrawX, nDrawY+1, right, nDrawY + height - 1 ); #else _wpi_rectangle( wnd->hdc, nDrawX, nDrawY, right, nDrawY + height); #endif /* if visible even with scrolling */ if( nDrawX < ( paint_right + hscroll_pos ) ) { if( bitmap > 0 ) { GUIDrawBitmap( bitmap, wnd->hdc, nDrawX, nDrawY, colour); } else { #ifdef __OS2_PM__ nDrawY += _wpi_metricdescent( GUItm ); #endif old_rop = _wpi_setrop2( wnd->hdc, R2_COPYPEN ); SetText( wnd, fore, back ); _wpi_textout( wnd->hdc, nDrawX, nDrawY, text, num_chars ); } } /* restore old resources */ if( old_rop != 0 ) { _wpi_setrop2( wnd->hdc, old_rop ); } if( old_brush != (HBRUSH)NULL ) { _wpi_getoldbrush( wnd->hdc, old_brush ); } if( brush != (HBRUSH)NULL ) { _wpi_deletebrush( brush ); } if( old_pen != (HPEN)NULL ) { _wpi_getoldpen( wnd->hdc, old_pen ); } if( pen != (HPEN)NULL ) { _wpi_deletepen( pen ); } } }