Click here to Skip to main content
15,887,683 members
Home / Discussions / Graphics
   

Graphics

 
GeneralRe: use System.Drawing namespace; Pin
Sam Marrocco27-Jan-15 2:35
Sam Marrocco27-Jan-15 2:35 
QuestionRotate TTF Font Glyph? Pin
radarcontact29-Nov-14 14:25
radarcontact29-Nov-14 14:25 
QuestionDx installation Pin
Otekpo Emmanuel20-Nov-14 19:20
Otekpo Emmanuel20-Nov-14 19:20 
AnswerRe: Dx installation Pin
Richard MacCutchan20-Nov-14 21:52
mveRichard MacCutchan20-Nov-14 21:52 
GeneralRe: Dx installation Pin
Otekpo Emmanuel20-Nov-14 23:29
Otekpo Emmanuel20-Nov-14 23:29 
GeneralRe: Dx installation Pin
Richard MacCutchan20-Nov-14 23:47
mveRichard MacCutchan20-Nov-14 23:47 
GeneralRe: Dx installation Pin
Jochen Arndt21-Nov-14 0:24
professionalJochen Arndt21-Nov-14 0:24 
QuestionMeasuring of Text with Multiple Fonts in One Single Line Pin
paul116730-Oct-14 21:59
paul116730-Oct-14 21:59 
I am following a request to write C++ code for a label that contains several text elements in one single line, varying by font, size, color.... Ok, that can be done easily in GDI+ by measuring each element's width and then execute a DrawString for each of the text elements starting at its calculated position.

So far, I failed miserably. Confused | :confused: Mad | :mad:
The horizontal text positions did not appear to be correct. I reverted now to very simple text measuring tests which confused me even more.

Test 1: Use of MeasureString
With the same font, the width of the string "MM" does not match the double with of the string "M". This cannot be explained with eventual rounding problems.

Test2: Use of MeasureCharacterRanges
Used the same font as for the first test. The width of "MM" is now exactly double of the width of "M". But: The width of the "M" ist lightyears away from the measurement result in the first test.

Here's the code I have used for the two tests:
C++
void ApplWindow_TextDrawTest(HDC hDC)
{
	Gdiplus::Graphics *G = new Gdiplus::Graphics(hDC);
	G->SetTextRenderingHint(TextRenderingHint::TextRenderingHintClearTypeGridFit);

	Gdiplus::StringFormat MyFormat;
	MyFormat.SetAlignment(Gdiplus::StringAlignment::StringAlignmentNear);
	MyFormat.SetFormatFlags(Gdiplus::StringFormatFlags::StringFormatFlagsNoWrap);

	Gdiplus::Font TextFont(L"Calibri", 36, Gdiplus::FontStyle::FontStyleBold, Gdiplus::Unit::UnitPoint);

	const wchar_t *Text1M = L"M";
	Gdiplus::PointF TextOrigin1M(0, 0);
	Gdiplus::RectF TextBounds1M;

	const wchar_t *Text2M = L"MM";
	Gdiplus::PointF TextOrigin2M(0, 50);
	Gdiplus::RectF TextBounds2M;

	//--- Test #1:  using MeasureString ----------
	G->MeasureString(Text1M, (INT)wcslen(Text1M), &TextFont, TextOrigin1M, &MyFormat, &TextBounds1M);
	G->MeasureString(Text2M, (INT)wcslen(Text2M), &TextFont, TextOrigin2M, &MyFormat, &TextBounds2M);
	//--- Results:  Text 1 Width=  59.218  ("M")
	//---           Text 2 Width= 102.427  ("MM")

	//--- Test #2:  using MeasureCharacterRanges ----------
	Gdiplus::Status RCode;
	Gdiplus::RectF LayoutRect(0, 0, 1000, 100);
	Gdiplus::Region RegionsList[3];
	Gdiplus::CharacterRange CRanges[3];
	CRanges[0].First = 0; CRanges[0].Length = 1;
	CRanges[1].First = 1; CRanges[1].Length = 1;
	CRanges[2].First = 0; CRanges[2].Length = 2;
	MyFormat.SetMeasurableCharacterRanges(3, CRanges);
	G->MeasureCharacterRanges(Text2M, (INT)wcslen(Text2M), &TextFont, LayoutRect, &MyFormat, 3, RegionsList);
	RCode = RegionsList[0].GetBounds(&TextBounds1M, G);		// Result: Text 1 Width = 42.000  ("M")
	RCode = RegionsList[1].GetBounds(&TextBounds1M, G);		// Result: Text 1 Width = 42.000  ("M"; the second char)
	RCode = RegionsList[2].GetBounds(&TextBounds2M, G);		// Result: Text 2 Width = 84.000  ("MM")

	//--- End of Test ---
	delete G;
}


Drawing of text with GDI+ gives me very nice results, that's why GDI+ is my first choice here. Does anybody have an idea how I can measure my texts correctly?
Thanks in advance.
AnswerRe: Measuring of Text with Multiple Fonts in One Single Line Pin
paul116731-Oct-14 2:12
paul116731-Oct-14 2:12 
GeneralRe: Measuring of Text with Multiple Fonts in One Single Line Pin
PaulB482-Nov-14 2:22
PaulB482-Nov-14 2:22 
GeneralRe: Measuring of Text with Multiple Fonts in One Single Line Pin
paul116713-Nov-14 22:17
paul116713-Nov-14 22:17 
QuestionImage editor control for asp.net Pin
Member 111274939-Oct-14 19:22
Member 111274939-Oct-14 19:22 
AnswerRe: Image editor control for asp.net Pin
Garth J Lancaster9-Oct-14 19:33
professionalGarth J Lancaster9-Oct-14 19:33 
QuestionPNG vs JPG Pin
V.11-Sep-14 19:46
professionalV.11-Sep-14 19:46 
AnswerRe: PNG vs JPG Pin
Peter_in_278011-Sep-14 20:51
professionalPeter_in_278011-Sep-14 20:51 
AnswerRe: PNG vs JPG Pin
Pete O'Hanlon11-Sep-14 21:01
mvePete O'Hanlon11-Sep-14 21:01 
AnswerRe: PNG vs JPG Pin
Chris Losinger2-Dec-14 4:31
professionalChris Losinger2-Dec-14 4:31 
QuestionBezier Curve issue Pin
pvpeng4-Jul-14 4:16
pvpeng4-Jul-14 4:16 
QuestionRe: Bezier Curve issue Pin
Richard Deeming4-Jul-14 4:39
mveRichard Deeming4-Jul-14 4:39 
AnswerRe: Bezier Curve issue Pin
Richard MacCutchan4-Jul-14 5:53
mveRichard MacCutchan4-Jul-14 5:53 
AnswerRe: Bezier Curve issue Pin
Bernhard Hiller13-Jul-14 21:58
Bernhard Hiller13-Jul-14 21:58 
QuestionHelp calculating a perpendicular line end point. Pin
Austin_Cpp28-Jun-14 10:58
Austin_Cpp28-Jun-14 10:58 
AnswerRe: Help calculating a perpendicular line end point. Pin
Yang Kok Wah29-Jun-14 0:33
Yang Kok Wah29-Jun-14 0:33 
GeneralRe: Help calculating a perpendicular line end point. Pin
Austin_Cpp1-Jul-14 18:41
Austin_Cpp1-Jul-14 18:41 
QuestionHow to write glutSwapBuffers() in SharpGL format? Pin
pvpeng27-Jun-14 11:05
pvpeng27-Jun-14 11:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.