Exemple #1
0
EXPORT_C TSize THuiFont::LineExtentsL(const TDesC& aTextString)
	{
	if (aTextString.Length() == 0)
    	{
    	// Zero length strings have extents of zero.
        return TSize(0, 0);
    	}
	
    // Retrieve the CFont object used when rasterizing this text mesh.
	CFont* font = NearestFontL();
    TSize textSize( MeasureBidiTextBoundsWidth(*font, aTextString, CFont::TMeasureTextInput::EFVisualOrder), 
                    font->FontMaxHeight());
    
    const CAknLayoutFont* layoutFont = 0;
    if (CCoeEnv::Static())
        {
        layoutFont = CAknLayoutFont::AsCAknLayoutFontOrNull( font );
        }
    
    if ( layoutFont )
        {
        textSize.iHeight = font->HeightInPixels();
        TInt textPaneHeight = layoutFont->TextPaneHeight();
        TInt textPaneTopToBaseline = layoutFont->TextPaneTopToBaseline();
        
        textSize.iHeight += textPaneHeight - textPaneTopToBaseline;
        textSize.iHeight += KHuiFontVerticalShiftInPixels;
        }
    else
        {
        textSize.iHeight = Max(textSize.iHeight, font->HeightInPixels());
        textSize.iHeight += 3; // the best approximation - fails on big (>=72) fonts
        }
        
    // Return the calculated text size.
    return textSize;
	}
Exemple #2
0
void CHelloControl::Draw(const TRect& /* aRect */) const
	{
	// draw surrounding rectangle
	SystemGc().DrawRect(Rect());
	// calculate rectangle to draw into
	TRect rect = Rect();
	rect.Shrink(1, 1);
	// calculate vertical centering
	CFont *font = iMessageFont;
	TInt ascent = (rect.Height() - font->HeightInPixels()) / 2
			+ font->AscentInPixels();
	// draw text in rectangle
	CWindowGc& gc = SystemGc();
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	gc.UseFont(iMessageFont);
	switch (Phase())
		{
		case 0:
			gc.DrawText(KTxtDrawCase0, rect, ascent, CGraphicsContext::ECenter,
					0);
			break;
		case 1:
			gc.DrawText(KTxtDrawCase1, rect, ascent, CGraphicsContext::ECenter,
					0);
			break;
		case 2:
			gc.DrawText(KTxtDrawCase2, rect, ascent, CGraphicsContext::ECenter,
					0);
			break;
		case 3:
			gc.DrawText(KTxtDrawCase3, rect, ascent, CGraphicsContext::ECenter,
					0);
			break;
		case 4:
			gc.DrawText(KTxtDrawCase4, rect, ascent, CGraphicsContext::ECenter,
					0);
			break;
		case 5:
			gc.DrawText(KTxtDrawCase5, rect, ascent, CGraphicsContext::ECenter,
					0);
			break;
		case 6:
			gc.DrawText(KTxtDrawCase6, rect, ascent, CGraphicsContext::ECenter,
					0);
			break;
		default:
			break;
		};
	}
Exemple #3
0
void CFontControl::Draw(const TRect& /* aRect */) const
	{
	// setup screen for example
	CWindowGc& gc = SystemGc();
	gc.Clear();

	// create a centered rectangle of the default size
	TRect drawRect = Rect();

	// set up absolute font-spec and text box for 300 twips font
	TFontSpec fontSpec(iCurrentFont, 300);
	// find the nearest font to the specified one
	CFont* drawFont;
	iDeviceMap->GetNearestFontInTwips(drawFont, fontSpec);
	// use it for this graphics context
	gc.UseFont(drawFont);

	// get font height
	TInt textHeight = drawFont->HeightInPixels();

	// set up the positioning of the character set rows
	TInt exampleMargin = 0;
	TInt currentOffset = ((drawRect.Height() + textHeight) / 2) - (TInt) (textHeight * 2.4);

	// set up descriptors to hold Unicode characters 32 to 255
	TBuf<50> buffer;
	TInt endPoint[6] =
		{
		64, 96, 138, 182, 216, 255
		};
	TInt count = 32;
	for (TInt pass = 0; pass <= 5; pass++)
		{
		while (count <= endPoint[pass])
			{
			buffer.Append((TUint) count);
			count++;
			}
		// draw the row in the current font
		gc.DrawText(buffer, drawRect, currentOffset,
				CGraphicsContext::ECenter, exampleMargin);
		currentOffset = currentOffset + (TInt) (textHeight * 1.2);
		buffer.Zero();
		}

	// discard and release font
	gc.DiscardFont();
	iDeviceMap->ReleaseFont(drawFont);
	}
void CCalendarManagerContainer::DrawSchedule(CWindowGc& gc, const TRect& aRect, const TRgb& p_Default_Font_Color1, const CFont& p_Font) const
	{		
	g_Pos_Y += g_Space_Y;	
	gc.SetPenColor(p_Default_Font_Color1);
	TInt i_Count = GetScheduleCount();
	
	if (i_Count == 0)
		{		
		gc.DrawText(_L("\x6CA1\x6709\x65E5\x7A0B"), TRect(0, 0, aRect.Width(), g_Pos_Y), (g_Pos_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels(), CGraphicsContext::ECenter, 0);
		}			
	else
		{
		TBuf<20> i_NUM;
		i_NUM.Append(_L("\x6709"));
		i_NUM.AppendNum(i_Count);
		i_NUM.Append(_L("\x4E2A\x65E5\x7A0B"));
		
		gc.DrawText(i_NUM, TRect(0, 0, aRect.Width(), g_Pos_Y), (g_Pos_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels(), CGraphicsContext::ECenter, 0);
		}
	//gc.DrawLine(TPoint(0, g_Pos_Y), TPoint(aRect.Width(), g_Pos_Y));	
	}
void CCalendarManagerContainer::DrawWeek(CWindowGc& gc, const TRect& aRect, const TRgb& p_Default_Font_Color1, const CFont& p_Font) const
	{
	gc.SetPenColor(p_Default_Font_Color1);
	gc.SetUnderlineStyle(EUnderlineOff);
	
	TInt i_Pos_X = 0;
	TInt i_Pos_Y = g_Pos_Y;
	
	for (TInt i = 0;i < sizeof(g_CalendarClass->g_Week) / sizeof(TInt);i++)
		{
		TBuf<10> i_Num;
		i_Num.AppendNum(g_CalendarClass->g_Week[i]);
		
		gc.DrawText(i_Num, TRect(i_Pos_X, i_Pos_Y, i_Pos_X + g_Space_X, i_Pos_Y + g_Space_Y), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels() + 1, CGraphicsContext::ECenter, 0);
		i_Pos_Y += g_Space_Y + 2;
		}					
	}
void CCalendarManagerContainer::DrawCurrentDay(CWindowGc& gc, MAknsSkinInstance* p_BgSkin, const TRgb& p_Default_Select_Color, const CFont& p_Font) const
	{
	TInt i_Col = (g_CalendarClass->g_SelectDay + g_CalendarClass->g_FirstWeek - 1) % 7 + 2;
	TInt i_Row = (g_CalendarClass->g_SelectDay + g_CalendarClass->g_FirstWeek - 1) / 7 + 1;
	
	TInt i_Pos_X = (i_Col - 1) * g_Space_X + i_Col - 1;
	TInt i_Pos_Y = (i_Row - 1) * g_Space_Y + (i_Row - 1) * 2 + g_Pos_Y;
		
	TRect i_OuterRect(i_Pos_X, i_Pos_Y, i_Pos_X + g_Space_X + 1, i_Pos_Y + g_Space_Y + 2);
	i_OuterRect.Shrink(2, 2);
	TRect i_InnerRect(i_OuterRect);
	i_InnerRect.Shrink(4, 4);
	
	AknsDrawUtils::DrawFrame(p_BgSkin, gc, i_OuterRect, i_InnerRect, KAknsIIDQsnFrList, KAknsIIDQsnFrListCenter);
	
	gc.SetPenColor(p_Default_Select_Color);
	TBuf<5> i_Num;
	i_Num.AppendNum(g_CalendarClass->g_SelectDay);	
	
	if (g_CalendarClass->g_SelectYear == g_CalendarClass->g_Year && g_CalendarClass->g_SelectMonth == g_CalendarClass->g_Month && g_CalendarClass->g_SelectDay == g_CalendarClass->g_Day)		
		gc.SetUnderlineStyle(EUnderlineOn);		
	else				
		gc.SetUnderlineStyle(EUnderlineOff);
				
	gc.DrawText(i_Num, TRect(i_Pos_X, i_Pos_Y, i_Pos_X + g_Space_X, i_Pos_Y + g_Space_Y), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels() + 1, CGraphicsContext::ECenter, 0);	
	}
void CCalendarManagerContainer::DrawDay(CWindowGc& gc, const TRect& aRect, const TRgb& p_Default_Font_Color1, const TRgb& p_Default_Font_Color2, const CFont& p_Font) const
	{
	gc.SetPenColor(p_Default_Font_Color1);
	
	TInt i_Total = 0;
	TInt i_WeekPos = g_CalendarClass->g_FirstWeek;	
	//TInt i_Pos_X = g_Space_X * (i_WeekPos + 1) + i_WeekPos + 1;
	//TInt i_Pos_Y = g_Pos_Y;
	
	TInt i_Pos_X = g_Space_X + 1;
	TInt i_Pos_Y = g_Pos_Y;
	
	if (i_WeekPos != 7)
		{
		gc.SetPenColor(p_Default_Font_Color2);
		for (TInt i = g_CalendarClass->g_MaxDay_PreMonth - i_WeekPos + 1;i <= g_CalendarClass->g_MaxDay_PreMonth;i++)
			{
			TBuf<5> i_Num;
			i_Num.AppendNum(i);
			
			gc.DrawText(i_Num, TRect(i_Pos_X, i_Pos_Y, i_Pos_X + g_Space_X, i_Pos_Y + g_Space_Y), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels() + 1, CGraphicsContext::ECenter, 0);
			
			i_Pos_X += g_Space_X + 1;
			i_Total++;
			}
		}
	
	i_Pos_X = g_Space_X * (i_WeekPos + 1) + i_WeekPos + 1;
	
	for (TInt i = 1; i <= g_CalendarClass->g_MaxDay; i++)
		{
		TBuf<5> i_Num;
		i_Num.AppendNum(i);
		
		if (i_WeekPos == 0)
			gc.SetPenColor(KRgbRed);
		else
			gc.SetPenColor(p_Default_Font_Color1);
			
		if (g_CalendarClass->g_SelectYear == g_CalendarClass->g_Year && g_CalendarClass->g_SelectMonth == g_CalendarClass->g_Month && i == g_CalendarClass->g_Day)			
			gc.SetUnderlineStyle(EUnderlineOn);		
		else			
			gc.SetUnderlineStyle(EUnderlineOff);			
		
		gc.DrawText(i_Num, TRect(i_Pos_X, i_Pos_Y, i_Pos_X + g_Space_X, i_Pos_Y + g_Space_Y), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels() + 1, CGraphicsContext::ECenter, 0);
				
		i_WeekPos++;		
		if (i_WeekPos >= 7)
			{
			i_WeekPos = 0;			
			i_Pos_Y += g_Space_Y + 2;			
			}				
		
		i_Pos_X = g_Space_X * (i_WeekPos + 1) + i_WeekPos + 1;
		i_Total++;
		}
	
	TInt j = 1;
	gc.SetPenColor(p_Default_Font_Color2);
	for (TInt i = i_Total + 1;i <= 42;i++)
		{
		TBuf<5> i_Num;
		i_Num.AppendNum(j);
		
		gc.DrawText(i_Num, TRect(i_Pos_X, i_Pos_Y, i_Pos_X + g_Space_X, i_Pos_Y + g_Space_Y), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels() + 1, CGraphicsContext::ECenter, 0);
		
		i_WeekPos++;		
		if (i_WeekPos >= 7)
			{
			i_WeekPos = 0;			
			i_Pos_Y += g_Space_Y + 2;
			}
			
		i_Pos_X = g_Space_X * (i_WeekPos + 1) + i_WeekPos + 1;		
		j++;
		}
	}
void CCalendarManagerContainer::DrawWeekName(CWindowGc& gc, const TRect& aRect, const TRgb& p_Default_Font_Color1, const CFont& p_Font) const
	{
	//TInt i_Pos_X = g_Space_X + 1;
	TInt i_Pos_X = 0;
	TInt i_Width = 0;
	TInt i_Height = g_Pos_Y + g_Space_Y;
	
	gc.SetPenColor(p_Default_Font_Color1);
	i_Width = i_Pos_X + g_Space_X;
	gc.DrawText(_L("\x5468"), TRect(i_Pos_X, g_Pos_Y, i_Width, i_Height), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels(), CGraphicsContext::ECenter, 0);
	i_Pos_X += g_Space_X + 1;
	
	for (TInt i = 0;i < 7;i++)
		{
		switch (i)
			{
			case 0:
				i_Width = i_Pos_X + g_Space_X;
				gc.DrawText(_L("\x65E5"), TRect(i_Pos_X, g_Pos_Y, i_Width, i_Height), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels(), CGraphicsContext::ECenter, 0);
				i_Pos_X += g_Space_X + 1;
				break;
				
			case 1:
				i_Width = i_Pos_X + g_Space_X;
				gc.DrawText(_L("\x4E00"), TRect(i_Pos_X, g_Pos_Y, i_Width, i_Height), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels(), CGraphicsContext::ECenter, 0);
				i_Pos_X += g_Space_X + 1;
				break;
				
			case 2:
				i_Width = i_Pos_X + g_Space_X;
				gc.DrawText(_L("\x4E8C"), TRect(i_Pos_X, g_Pos_Y, i_Width, i_Height), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels(), CGraphicsContext::ECenter, 0);
				i_Pos_X += g_Space_X + 1;
				break;
				
			case 3:
				i_Width = i_Pos_X + g_Space_X;
				gc.DrawText(_L("\x4E09"), TRect(i_Pos_X, g_Pos_Y, i_Width, i_Height), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels(), CGraphicsContext::ECenter, 0);
				i_Pos_X += g_Space_X + 1;
				break;
				
			case 4:
				i_Width = i_Pos_X + g_Space_X;
				gc.DrawText(_L("\x56DB"), TRect(i_Pos_X, g_Pos_Y, i_Width, i_Height), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels(), CGraphicsContext::ECenter, 0);
				i_Pos_X += g_Space_X + 1;
				break;
				
			case 5:
				i_Width = i_Pos_X + g_Space_X;
				gc.DrawText(_L("\x4E94"), TRect(i_Pos_X, g_Pos_Y, i_Width, i_Height), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels(), CGraphicsContext::ECenter, 0);
				i_Pos_X += g_Space_X + 1;
				break;
				
			case 6:				
				i_Width = i_Pos_X + g_Space_X;
				gc.DrawText(_L("\x516D"), TRect(i_Pos_X, g_Pos_Y, i_Width, i_Height), (g_Space_Y - p_Font.HeightInPixels()) / 2 + p_Font.HeightInPixels(), CGraphicsContext::ECenter, 0);
				i_Pos_X += g_Space_X + 1;
				break;
			}			
		}
	
	g_Pos_Y += g_Space_Y;
	//gc.DrawLine(TPoint(0, g_Pos_Y), TPoint(aRect.Width(), g_Pos_Y));
	}
Exemple #9
0
void CTScreenDevice::TwipsCacheFlushL()
	{
	RWsSession session;
	CWsScreenDevice* device;
	CFont* font;
	CFont* font2;
	const TFontSpec fontspec(KTestFontTypefaceName,250);
	TPixelsTwipsAndRotation sizeAndRotation;

	// create a CWsScreenDevice instance
	User::LeaveIfError(session.Connect());
	device=new(ELeave) CWsScreenDevice(session);
	device->Construct(iTest->iScreenNumber);

	// Record a font height for use by latter tests
	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font,fontspec));
	const TInt height0=font->HeightInPixels();
	device->ReleaseFont(font);

	// 1. find font with best-matching height in twips,
	// 2. change twips size of the screen (leaving pixel-size same),
	// 3. find font with best-matching height in twips,
	// 4. make sure that the newly found font is not the same as previous and has the different height in pixels
	device->GetDefaultScreenSizeAndRotation(sizeAndRotation);
#if defined(EXTRA_LOGGING)
	_LIT(KLog1,"Font height: %d for unchanged device.   pixels=%d,%d  twips=%d,%d");
	LOG_MESSAGE6(KLog1,height0,sizeAndRotation.iPixelSize.iWidth,sizeAndRotation.iPixelSize.iHeight
						,sizeAndRotation.iTwipsSize.iWidth,sizeAndRotation.iTwipsSize.iHeight);
#endif
	sizeAndRotation.iTwipsSize.iHeight=2000;
	sizeAndRotation.iTwipsSize.iWidth =3000;
	device->SetScreenSizeAndRotation(sizeAndRotation);

	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font,fontspec));
	TInt height=font->HeightInPixels();
#if defined(EXTRA_LOGGING)
	_LIT(KLog2,"Font height: %d for device with twips set to 2000x3000");
	LOG_MESSAGE2(KLog2,height);
#endif
	TFontSpec returnedSpec=font->FontSpecInTwips();

	sizeAndRotation.iTwipsSize.iHeight=4000;
	sizeAndRotation.iTwipsSize.iWidth =6000;
	device->SetScreenSizeAndRotation(sizeAndRotation);

	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font2,fontspec));
	TInt height2=font2->HeightInPixels();
	TFontSpec returnedSpec2 = font2->FontSpecInTwips();
#if defined(EXTRA_LOGGING)
	_LIT(KLog3,"Font height: %d for device with twips set to 4000x6000");
	LOG_MESSAGE2(KLog3,height2);
#endif

	TEST(font!=font2);
	TEST(height!=height2);
	_LIT(KLogErrM,"Font Heights in pixels match unexpectantly, height=%d");
	if (height==height2)
		INFO_PRINTF2(KLogErrM,height);

	device->ReleaseFont(font2);
	device->ReleaseFont(font);

	// 1. find font with best-matching height in twips,
	// 2. change pixel size of the screen (leaving twip-size same),
	// 3. find font with best-matching height in twips,
	// 4. make sure that the newly found font is not the same as previous and has the different height in pixels
	device->GetDefaultScreenSizeAndRotation(sizeAndRotation);
	sizeAndRotation.iPixelSize.iHeight=240;
	sizeAndRotation.iPixelSize.iWidth =640;
	device->SetScreenSizeAndRotation(sizeAndRotation);

	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font,fontspec));
	height=font->HeightInPixels();
	returnedSpec=font->FontSpecInTwips();
#if defined(EXTRA_LOGGING)
	_LIT(KLog4,"Font height: %d for device with pixels set to 240x640   twips=%d,%d");
	LOG_MESSAGE4(KLog4,height,sizeAndRotation.iTwipsSize.iWidth,sizeAndRotation.iTwipsSize.iHeight);
#endif

	sizeAndRotation.iPixelSize.iHeight=480;
	sizeAndRotation.iPixelSize.iWidth =1280;
	device->SetScreenSizeAndRotation(sizeAndRotation);

	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font2,fontspec));
	height2=font2->HeightInPixels();
	returnedSpec2=font2->FontSpecInTwips();
#if defined(EXTRA_LOGGING)
	_LIT(KLog5,"Font height: %d for device with pixels set to 480x1280");
	LOG_MESSAGE2(KLog5,height2);
#endif

	TEST(font!=font2);
	TEST(height!=height2);
	if (height==height2)
		INFO_PRINTF2(KLogErrM,height);

	device->ReleaseFont(font2);
	device->ReleaseFont(font);

	// 1. double the width and height of screen in both pixels and twips
	// 2. find font with best-matching height in twips,
	// 3. make sure that the newly found font is the same as previous and has the same height in pixels
	device->GetDefaultScreenSizeAndRotation(sizeAndRotation);
	device->SetScreenSizeAndRotation(sizeAndRotation);
	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font,fontspec));
	sizeAndRotation.iPixelSize.iHeight*=2;
	sizeAndRotation.iPixelSize.iWidth *=2;
	sizeAndRotation.iTwipsSize.iHeight*=2;
	sizeAndRotation.iTwipsSize.iWidth *=2;
	device->SetScreenSizeAndRotation(sizeAndRotation);

	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font2,fontspec));
	height2=font2->HeightInPixels();
#if defined(EXTRA_LOGGING)
	_LIT(KLog6,"Font height: %d for device doubled size.   pixels=%d,%d  twips=%d,%d");
	LOG_MESSAGE6(KLog6,height2,sizeAndRotation.iPixelSize.iWidth,sizeAndRotation.iPixelSize.iHeight
							,sizeAndRotation.iTwipsSize.iWidth,sizeAndRotation.iTwipsSize.iHeight);
#endif

	TEST(font==font2);
	TEST(height0==height2);
	_LIT(KLogErrD,"Font Heights in pixels don't match, expected=%d, actual=%d");
	if (height0!=height2)
		INFO_PRINTF3(KLogErrD,height0,height2);

	device->ReleaseFont(font2);
	device->ReleaseFont(font);

	// 1. swap width and height sizes of screen for both pixels and twips
	// 2. find font with best-matching height in twips,
	// 3. make sure that the newly found font is the same as previous and has the same height in pixels
	device->GetDefaultScreenSizeAndRotation(sizeAndRotation);
	device->SetScreenSizeAndRotation(sizeAndRotation);
	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font,fontspec));
	TInt swap=sizeAndRotation.iPixelSize.iHeight;
	sizeAndRotation.iPixelSize.iHeight=sizeAndRotation.iPixelSize.iWidth;
	sizeAndRotation.iPixelSize.iWidth =swap;
	swap=sizeAndRotation.iTwipsSize.iHeight;
	sizeAndRotation.iTwipsSize.iHeight=sizeAndRotation.iTwipsSize.iWidth;
	sizeAndRotation.iTwipsSize.iWidth =swap;
	device->SetScreenSizeAndRotation(sizeAndRotation);
	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font2,fontspec));
	height2 = font2->HeightInPixels();
#if defined(EXTRA_LOGGING)
	_LIT(KLog7,"Font height: %d for device rotated size.   pixels=%d,%d  twips=%d,%d");
	LOG_MESSAGE6(KLog7,height2,sizeAndRotation.iPixelSize.iWidth,sizeAndRotation.iPixelSize.iHeight
							,sizeAndRotation.iTwipsSize.iWidth,sizeAndRotation.iTwipsSize.iHeight);
#endif

	TEST(font==font2);
	TEST(height0==height2);
	if (height0!=height2)
		INFO_PRINTF3(KLogErrD,height0,height2);

	device->ReleaseFont(font2);
	device->ReleaseFont(font);

	delete device;
	session.Close();
	}