Click here to Skip to main content
15,884,836 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
JokeRe: Why "make"? Pin
Richard MacCutchan7-Feb-19 22:19
mveRichard MacCutchan7-Feb-19 22:19 
GeneralRe: Why "make"? Pin
CPallini7-Feb-19 23:05
mveCPallini7-Feb-19 23:05 
GeneralRe: Why "make"? Pin
Dar Brett8-Feb-19 16:02
Dar Brett8-Feb-19 16:02 
GeneralRe: Why "make"? Pin
CPallini9-Feb-19 0:22
mveCPallini9-Feb-19 0:22 
Questionmemory device context coordinates Pin
Alexander Kindel6-Feb-19 12:12
Alexander Kindel6-Feb-19 12:12 
AnswerRe: memory device context coordinates Pin
mo14926-Feb-19 13:30
mo14926-Feb-19 13:30 
GeneralRe: memory device context coordinates Pin
Alexander Kindel6-Feb-19 13:44
Alexander Kindel6-Feb-19 13:44 
AnswerRe: memory device context coordinates Pin
leon de boer6-Feb-19 15:55
leon de boer6-Feb-19 15:55 
You are dealing with TTF glyphs not a bitmap and you will need to understand how FUnits and the EMSquare work
TrueType fundamentals - Typography | Microsoft Docs[^]
The glyph is rendered to screen it never is a bitmap.

Now what you could do if font style isn't important is select a bitmap font and it will work much as you think.

Now if you want to do what you are doing with a TTF the function you want is called
GetGlyphOutlineA function | Microsoft Docs[^]
The DC will be your window you are drawing the text on so it matches one to one.

Now the problem is you will have an outline with beziers and lines and to be able to decide if you are in or out you need to scanline the contour at the y value and see if the point is between any two runline points of the scanline. Now if you follow all that this is the two scanline functions you need

/*-ScanlineLine2D-----------------------------------------------------------
 Scanline (sy) intersect and the line between the two vertices. The return
 will be 0 for no intersect or 1 and px will contain x intersect value.
 A horizontal line on the scan line will return no points as is consistant
 with scan lining.
 ---------------------------------------------------------------------------*/
short ScanlineLine2D(long x1, long y1,				// Vertex 1 (x1,y1)
					 long x2, long y2,				// Vertex 2 (x2,y2)
                     long sy, 		                // Scan line y value
                     long* px1){					// X interection pt
    long xt;
	double t;

	if (y2 == y1) return (0);										// Trivial fail horizontal line even if coincides with sy
	if (((sy >= y1) && (sy <= y2)) || ((sy >= y2) && (sy <= y1))){	// Check sy within range between y1 and y2
		
		// yt = (y2-y1)*t + y1		where 0 <= t <= 1, 
		// Re-arranging  t = (yt - y1)/(y2-y1)
		// Our yt value will be sy-epsilon so we don't get single corner points
		// t = ((sy-epsilon) - y1)/(y2-y1)
		// Re-arranging for floats   t = ((sy-y1)-epsilon)/(y2-y1)
		t = ((double)(sy-y1)-FLT_EPSILON)/(double)(y2-y1);		// Calculate t value

		if ( (t >= 0.0) && (t <= 1.0)) {				// Check valid 't'  0.0 <= t <= 1.0
			// xt = (x2-x1)*t + x1		where 0 <= t <= 1 
			xt = (long)((double)(x2-x1)*t) + x1;				// Calculate x at 't'
			if (px1) (*px1) = xt;											// Update intersect point x value
			return (1);												// We have 1 interesect point
		} else return (0);											// Invalid t value no intersection
	} else return (0);												// Return zero sy not in y1-y2 range
}


/*-ScanlineQuadBezier2D-----------------------------------------------------
 Scanline (sy) intersect and the quad bezier between the 3 control points.
 The return will be 0 for no intersect, 1 and px1 will contain x intersect 
 value or 2 and px1 and px2 will contain the x interect values.
 ---------------------------------------------------------------------------*/
short ScanlineQuadBezier2D(long x1, long y1,			// Vertex 1 (x1,y1) = On grid start pt
						   long x2, long y2,			// Vertex 2 (x2,y2) = Control Pt
						   long x3, long y3,			// Vertex 3 (x1,y1) = On grid End point
               			   long sy, 							// Scan line y value
                     	   long* px1, long* px2){		// Interection pt(s)

    short rslt;
	long dx0, dy0, dx1, dy1, dx2, dy2, xf;
	long* px;
    double tmf, tdf, tf, ymf;

	dx0 = x2 - x1;													// X diff between x2 and x1
	dy0 = y2 - y1;													// Y diff between y2 and y1
	dx1 = x3 - x2;													// X diff between x3 and x2
	dy1 = y3 - y2;													// Y diff between y3 and y2
	if ((dx0 == 0) && (dy0 == 0) && (dx1 == 0) && (dy1 == 0))		// All 3 points are one and same
		return (0);													// Drop point even if coincides with sy	
	if ((dx0 == 0) && (dy0 == 0))									// First 2 points are one and same
		return (ScanlineLine2D(x2, y2, x3, y3, sy, px1));			// Scanline as a line from (x2,y2)<->(x3,y3)
	if((dx1 == 0) && (dy1 == 0))									// Last two points are one and same	
		return (ScanlineLine2D(x1, y1, x2, y2, sy, px1));			// Scanline as a line from (x1,y1)<->(x2,y2)
	dx2 = (dx1-dx0);												// Difference between dx1 and dx0
	dy2 = (dy1-dy0);												// Differnece between dy1 and dy0
	if (dy2 != 0){													// y(t) = a*t*t + b*t + c
		// Calculate apex
		tmf = -(double)dy0/(double)dy2;								// 't' at apex point
		ymf = (double)y1 + FLT_EPSILON + tmf*(double)dy0;		// y at apex point
		tdf = ((double)sy - ymf)/(double)dy2;						// ''t' value at scanline
		if (tdf < 0.0) {									// If t value is invalid
			return (0);												// No intersect
		} else if (tdf != 0.0) tdf = sqrt(tdf);				// Take sqrt of t value
		rslt = 0;													// Preset intersect return count to zero
		px = px1;													// Preset intersect x ptr to px1
		tf = tmf - tdf;												// Calculate first test t value
		if ((tf >= 0.0) && (tf <= 1.0)){				// Valid 't'  0.0 <= t <= 1.0
			xf = (long)(((double)dx2*tf + (double)(dx0*2))*tf) + x1;// Calculate x point of intersec
			(*px) = xf;												// Transfer that result to *px
			rslt++;													// Increment intersect count
			px = px2;												// Advance point to px2
		};
		tf = tmf + tdf;												// Calculate second test t value
		if ((tf >= 0.0) && (tf <= 1.0)){				// Valid 't'  0.0 <= t <= 1.0
			xf = (long)(((double)dx2*tf + (double)(dx0*2))*tf) + x1;// Calculate x point of intersect
			(*px) = xf;												// Transfer that result to *px
			rslt++;													// Increment intersect count
			px = px2;												// Advance ptr to px2
		};		
		return (rslt);												// We can have one or two points returned
	} else if (dy0 != 0) {											// y(t) = b*t + c
		tf = ((double)(sy - y1) - FLT_EPSILON)/(double)(dy0*2);	// Calculate t of intersect
		if  ((tf >= 0.0) && (tf <= 1.0)){			// Valid 't'  0.0 <= t <= 1.0
			xf = (long)(((double)dx2*tf + (double)(dx0*2))*tf) + x1;// Calculate x point of intersect		
			(*px1) = xf;											// Transfer that result to px1
			return (1);												// Return 1 as intersect count
		} else return (0);											// Intersect is outside line segment
	} else return (0);												// Drop horizontal line even if coincides with sy
}

In vino veritas

GeneralRe: memory device context coordinates Pin
Alexander Kindel7-Feb-19 23:23
Alexander Kindel7-Feb-19 23:23 
GeneralRe: memory device context coordinates Pin
leon de boer8-Feb-19 21:43
leon de boer8-Feb-19 21:43 
AnswerRe: memory device context coordinates Pin
Alexander Kindel8-Feb-19 9:22
Alexander Kindel8-Feb-19 9:22 
QuestionMenu bar on title bar of application Pin
jung-kreidler6-Feb-19 2:23
jung-kreidler6-Feb-19 2:23 
QuestionChanged CMDIChildWnd to CMDIChildWndEx: does not show anything inside the frame Pin
Dansveen4-Feb-19 2:02
Dansveen4-Feb-19 2:02 
Question_findfirst and fopen very slow Pin
cristiapi31-Jan-19 1:13
cristiapi31-Jan-19 1:13 
QuestionRe: _findfirst and fopen very slow Pin
David Crow31-Jan-19 3:50
David Crow31-Jan-19 3:50 
AnswerRe: _findfirst and fopen very slow Pin
cristiapi31-Jan-19 3:58
cristiapi31-Jan-19 3:58 
QuestionRe: _findfirst and fopen very slow Pin
David Crow31-Jan-19 4:23
David Crow31-Jan-19 4:23 
AnswerRe: _findfirst and fopen very slow Pin
cristiapi31-Jan-19 5:34
cristiapi31-Jan-19 5:34 
QuestionRe: _findfirst and fopen very slow Pin
David Crow31-Jan-19 6:01
David Crow31-Jan-19 6:01 
AnswerRe: _findfirst and fopen very slow Pin
cristiapi31-Jan-19 6:07
cristiapi31-Jan-19 6:07 
GeneralRe: _findfirst and fopen very slow Pin
David Crow31-Jan-19 6:14
David Crow31-Jan-19 6:14 
QuestionRe: _findfirst and fopen very slow Pin
jeron131-Jan-19 4:58
jeron131-Jan-19 4:58 
AnswerRe: _findfirst and fopen very slow Pin
cristiapi31-Jan-19 5:20
cristiapi31-Jan-19 5:20 
QuestionRe: _findfirst and fopen very slow Pin
David Crow31-Jan-19 6:04
David Crow31-Jan-19 6:04 
AnswerRe: _findfirst and fopen very slow Pin
cristiapi31-Jan-19 6:10
cristiapi31-Jan-19 6:10 

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.