void CPictureWidget::Draw(CGraphicsContext &aGc) const { if(iActive) { aGc.SetBrushStyle(CGraphicsContext::ENullBrush); aGc.SetPenStyle(CGraphicsContext::ESolidPen); aGc.SetPenColor(KRgbBlack); TRect rect(point,iSize); rect.Move(TPoint(0,-iTextHeight)); rect.Shrink(-1,-1); aGc.DrawRect(rect); } if(iBitmap) { aGc.DrawBitmap(TRect(point - TPoint(0,iTextHeight),iSize),iBitmap,TRect(iSize)); } else { const TDesC& text = /*((CPictureWidget&)element).*/Alt(); int width = CCoeEnv::Static()->NormalFont()->MeasureText(text); TRect rect(point,TSize(width,iTextHeight)); rect.Move(TPoint(0,-iTextHeight)); aGc.SetPenStyle(CGraphicsContext::ESolidPen); aGc.SetPenColor(KRgbYellow); aGc.DrawRect(rect); aGc.SetPenColor(KRgbBlue); aGc.DrawText(text,point); } }
EXPORT_C void CXzePicture::Draw(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aClipRect,MGraphicsDeviceMap* aMap) const // Draw this simple picture. // { aGc.Reset(); aGc.SetClippingRect(aClipRect); TSize size; // Size of graphics device in pixels GetSizeInPixels(aMap,size); TRect box; // The rectangle that exactly fits the picture box.iTl=aTopLeft; box.iBr.iX=aTopLeft.iX+size.iWidth; box.iBr.iY=aTopLeft.iY+size.iHeight; TRgb white(255,255,255); // First draw outer box and fill in rest of box. aGc.SetBrushColor(white); aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); aGc.DrawRect(box); // Now draw label CFont* font; TFontSpec fontSpec(_L("Arial"),213); if (aMap->GetNearestFontInTwips(font,fontSpec)<0) { return; } aGc.UseFont(font); TBuf<1> label; label.Append(iLabel); TInt baselineOffset=(box.Height()+font->AscentInPixels())/2; aGc.SetBrushStyle(CGraphicsContext::ENullBrush); aGc.DrawText(label,box,baselineOffset,CGraphicsContext::ECenter); aGc.DiscardFont(); aMap->ReleaseFont(font); }
void CTextWidget::Draw(CGraphicsContext &aGc) const { const TDesC& text = /*((CTextWidget&)element).*/Text(); //gc.DrawRect(rect); if(/*element.*/Link().Length()) //带链接 { int width = CCoeEnv::Static()->NormalFont()->MeasureText(text); //aGc.SetPenColor(KRgbBlue); if(iActive) { int textHeight = CCoeEnv::Static()->NormalFont()->HeightInPixels(); TRect rect(point,TSize(width,textHeight)); rect.Move(TPoint(0,-textHeight)); aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); aGc.SetBrushColor(KRgbBlue); aGc.SetPenStyle(CGraphicsContext::ENullPen); aGc.DrawRect(rect); aGc.SetPenColor(KRgbWhite); } else { aGc.SetBrushStyle(CGraphicsContext::ENullBrush); aGc.SetPenStyle(CGraphicsContext::ESolidPen); aGc.SetPenColor(KRgbBlue); } TPoint point1 = point; TPoint point2 = point1; point2.iX += width; aGc.DrawLine(point1,point2); } else //不带链接 { aGc.SetBrushStyle(CGraphicsContext::ENullBrush); aGc.SetPenStyle(CGraphicsContext::ESolidPen); aGc.SetPenColor(KRgbBlack); } aGc.DrawText(text,point); }
EXPORT_C void DrawUtils::DrawText(CGraphicsContext& aGc,const TDesC& aString,const TRect& aBox,TInt aBaseLineOffset, CGraphicsContext::TTextAlign aHoriz,TInt aMargin,const CFont* aFont) /** Draws text inside a rectangle. @param aGc The graphics context. @param aString The text string to draw. @param aBox The rectangle to draw the text in. @param aBaseLineOffset An offset from the top of the box to the text baseline. @param aHoriz The horizontal text alignment. @param aMargin The margin around the text. @param aFont The font to use. */ { // static if (aHoriz!=CGraphicsContext::ELeft) { const TInt extraWidth=aBox.Width()-aFont->TextWidthInPixels(aString)-aMargin; if (aHoriz==CGraphicsContext::ECenter) aMargin+=extraWidth/2; else aMargin=extraWidth; } aGc.DrawText(aString,aBox,aBaseLineOffset,CGraphicsContext::ELeft,aMargin); }
/** Draw text and its highlit background if any. The text should be drawn with its origin at aTextOrigin after optionally drawing the background in aRect; and the text should be expanded in width by aExtraPixels, normally by using letterspacing. The default function draws the text with no special effects and supports standard and rounded highlighting only. The font, colour, and text style, which are specified in aFormat, have already been selected into the graphics context. */ EXPORT_C void MTmCustomExtension::DrawText(CGraphicsContext& aGc,const TPoint& /*aTextLayoutTopLeft*/,const TRect& aRect, const TTmLineInfo& /*aLineInfo*/,const TTmCharFormat& aFormat, const TDesC& aText,const TInt aStart, const TInt aEnd, const TPoint& aTextOrigin,TInt aExtraPixels) const { TUint effects = aFormat.iEffects; CGraphicsContext::TTextParameters contextParam; contextParam.iStart = aStart; contextParam.iEnd = aEnd; // Draw the highlight. if (effects) { if (effects & TTmCharFormat::EBackground) { // Draw the background. if (!(effects & TTmCharFormat::ERounded)) { SetBrushColor(aGc,aFormat.iBackgroundColor); aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); aGc.SetPenStyle(CGraphicsContext::ENullPen); aGc.DrawRect(aRect); aGc.SetPenStyle(CGraphicsContext::ESolidPen); } // Draw the background with rounded corners. else { /* The pen is made solid, not null, and the pen colour is set, to work around some bugs in DrawRoundRect: see ER5U defect EDNGASR-487K64. */ SetBrushColor(aGc,aFormat.iBackgroundColor); aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); aGc.SetPenStyle(CGraphicsContext::ESolidPen); SetPenColor(aGc,aFormat.iBackgroundColor); TSize corner(Min(aRect.Height(),aRect.Width()) / 3,aRect.Height() / 3); aGc.DrawRoundRect(aRect,corner); //+ fill in flat side if needed; draw ordinary rectangle if both sides are flat. SetPenColor(aGc,aFormat.iTextColor); } } // Draw the text offset towards the bottom-right in the highlight colour before drawing in the text colour. else if (effects & TTmCharFormat::EShadow) { SetPenColor(aGc,aFormat.iBackgroundColor); if (aExtraPixels) aGc.SetCharJustification(aExtraPixels,aText.Length()); TPoint p(aTextOrigin); p.iX += 2; p.iY += 2; if (aStart < 0 || aEnd < 0) aGc.DrawText(aText,p); else aGc.DrawText(aText,&contextParam,p); SetPenColor(aGc,aFormat.iTextColor); } } // Draw the text, with letterspacing if needed. if (aExtraPixels) aGc.SetCharJustification(aExtraPixels,aText.Length()); if (aStart < 0 || aEnd < 0) aGc.DrawText(aText,aTextOrigin); else aGc.DrawText(aText,&contextParam,aTextOrigin); }