void AP_Preview_Annotation::draw(const UT_Rect *clip) { UT_UNUSED(clip); m_drawString = m_sDescription; UT_RGBColor FGcolor(0,0,0); UT_RGBColor BGcolor(m_clrBackground); m_pFont = m_gc->findFont("Times New Roman", "normal", "normal", "normal", "normal", "12pt", NULL); UT_ASSERT_HARMLESS(m_pFont); if(!m_pFont) { clearScreen(); return; } m_gc->setFont(m_pFont); m_iAscent = m_gc->getFontAscent(m_pFont); m_iDescent = m_gc->getFontDescent(m_pFont); m_iHeight = m_gc->getFontHeight(m_pFont); clearScreen(); // // Calculate the draw coordinates position // UT_sint32 iTop = m_gc->tlu(1); UT_sint32 len = m_drawString.size(); UT_sint32 iLeft = m_gc->tlu(2); // // Fill the background color // GR_Painter painter(m_gc); // // Do the draw chars at last! // m_gc->setColor(FGcolor); painter.drawChars(m_drawString.ucs4_str(), 0, len, iLeft, iTop); // bad hardcoded color, but this will probably [ <-this assumption is the bad thing :) ] never be different anyway m_gc->setColor(UT_RGBColor(0,0,0)); painter.drawLine(0, 0, m_gc->tlu(getWindowWidth()), 0); painter.drawLine(m_gc->tlu(getWindowWidth()) - m_gc->tlu(1), 0, m_gc->tlu(getWindowWidth()) - m_gc->tlu(1), m_gc->tlu(getWindowHeight())); painter.drawLine(m_gc->tlu(getWindowWidth()) - m_gc->tlu(1), m_gc->tlu(getWindowHeight()) - m_gc->tlu(1), 0, m_gc->tlu(getWindowHeight()) - m_gc->tlu(1)); painter.drawLine(0, m_gc->tlu(getWindowHeight()) - m_gc->tlu(1), 0, 0); }
/* * * Finally draw the characters in the preview. * */ void XAP_Preview_FontPreview::draw(void) { // // Get text decorations. // bool isUnder,isOver,isStrike; const std::string sDecor = getVal("text-decoration"); if(!sDecor.empty()) { isUnder = (NULL != strstr(sDecor.c_str(),"underline")); isOver = (NULL != strstr(sDecor.c_str(),"overline")); isStrike = (NULL != strstr(sDecor.c_str(),"line-through")); } else { isUnder = false; isOver = false; isStrike = false; } // // Do foreground and background colors. // UT_RGBColor FGcolor(0,0,0); const std::string sFGColor = getVal("color"); if(!sFGColor.empty()) UT_parseColor(sFGColor.c_str(),FGcolor); UT_RGBColor BGcolor(m_clrBackground); const std::string sBGColor = getVal("bgcolor"); if(!sBGColor.empty() && strcmp(sBGColor.c_str(),"transparent") != 0) UT_parseColor(sBGColor.c_str(),BGcolor); // // Get the font and bold/italic- ness // //GR_Font * pFont; std::string sFamily = getVal("font-family"); std::string sStyle = getVal("font-style"); std::string sVariant = getVal("font-variant"); std::string sStretch = getVal("font-stretch"); std::string sSize = getVal("font-size"); std::string sWeight = getVal("font-weight"); if(sFamily.empty()) sFamily = "Times New Roman"; if(sStyle.empty()) sStyle = "normal"; if(sVariant.empty()) sVariant = "normal"; if(sStretch.empty()) sStretch = "normal"; if(sSize.empty()) sSize="12pt"; if(sWeight.empty()) sWeight = "normal"; m_pFont = m_gc->findFont(sFamily.c_str(), sStyle.c_str(), sVariant.c_str(), sWeight.c_str(), sStretch.c_str(), sSize.c_str(), NULL); UT_ASSERT_HARMLESS(m_pFont); if(!m_pFont) { clearScreen(); return; } m_gc->setFont(m_pFont); m_iAscent = m_gc->getFontAscent(m_pFont); m_iDescent = m_gc->getFontDescent(m_pFont); m_iHeight = m_gc->getFontHeight(m_pFont); // // Clear the screen! // clearScreen(); // // Calculate the draw coordinates position // UT_sint32 iWinWidth = m_gc->tlu(getWindowWidth()); UT_sint32 iWinHeight = m_gc->tlu(getWindowHeight()); UT_sint32 iTop = (iWinHeight - m_iHeight)/2; UT_sint32 len = UT_UCS4_strlen(m_pszChars); UT_sint32 twidth = m_gc->measureString(m_pszChars,0,len,NULL); UT_sint32 iLeft = (iWinWidth - twidth)/2; // // Fill the background color // GR_Painter painter(m_gc); if(!sBGColor.empty()) painter.fillRect(BGcolor,iLeft,iTop,twidth,m_iHeight); // // Do the draw chars at last! // m_gc->setColor(FGcolor); painter.drawChars(m_pszChars, 0, len, iLeft, iTop); // // Do the decorations // if(isUnder) { UT_sint32 iDrop = iTop + m_iAscent + m_iDescent/3; painter.drawLine(iLeft,iDrop,iLeft+twidth,iDrop); } if(isOver) { UT_sint32 iDrop = iTop + m_gc->tlu(1) + (UT_MAX(m_gc->tlu(10),m_iAscent) - m_gc->tlu(10))/8; painter.drawLine(iLeft,iDrop,iLeft+twidth,iDrop); } if(isStrike) { UT_sint32 iDrop = iTop + m_iAscent * 2 /3; painter.drawLine(iLeft,iDrop,iLeft+twidth,iDrop); } // bad hardcoded color, but this will probably [ <-this assumption is the bad thing :) ] never be different anyway m_gc->setColor(UT_RGBColor(0,0,0)); painter.drawLine(0, 0, m_gc->tlu(getWindowWidth()), 0); painter.drawLine(m_gc->tlu(getWindowWidth()) - m_gc->tlu(1), 0, m_gc->tlu(getWindowWidth()) - m_gc->tlu(1), m_gc->tlu(getWindowHeight())); painter.drawLine(m_gc->tlu(getWindowWidth()) - m_gc->tlu(1), m_gc->tlu(getWindowHeight()) - m_gc->tlu(1), 0, m_gc->tlu(getWindowHeight()) - m_gc->tlu(1)); painter.drawLine(0, m_gc->tlu(getWindowHeight()) - m_gc->tlu(1), 0, 0); }