|
Update
I have added one more test which is using standard GDI, and I have changed the GDI+ font to units of pixels. Unfortunately, this third test shows results which do not match the previous results at all.
Does anybody have an idea why I get so different results?
Since I had not only added a third test but also changed the code of the first tests I am appending the full example here; the results I found have been added as comments:
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::UnitPixel);
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;
G->MeasureString(Text1M, (INT)wcslen(Text1M), &TextFont, TextOrigin1M, &MyFormat, &TextBounds1M);
G->MeasureString(Text2M, (INT)wcslen(Text2M), &TextFont, TextOrigin2M, &MyFormat, &TextBounds2M);
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); RCode = RegionsList[1].GetBounds(&TextBounds1M, G); RCode = RegionsList[2].GetBounds(&TextBounds2M, G);
int MapModeResult = SetMapMode(hDC, MM_TEXT); HFONT TextFont3 = CreateFont(36, 0, 0, 0, FW_BOLD, false, false, false, ANSI_CHARSET, OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH | FF_DONTCARE, L"Calibri");
HGDIOBJ PrevFont = SelectObject(hDC, TextFont3);
ABCFLOAT ABCCharData;
BOOL RFlg = GetCharABCWidthsFloat(hDC, (UINT)'M', (UINT)'M', &ABCCharData);
delete G;
}
|
|
|
|
|
You should try -36 as font size in your test#3, this matches the font size chosen in the other tests.
Try better
|
|
|
|
|
I think I found the answer to my question:
GDI and GDI+ do both not resolve by fractions of pixels. That is mainly why my measurement result and the rendered output do not match in all situations.
I have now received an advice from a friend to take a closer look into the features of DirectWrite. Indeed, this engine appears to be the solution for my demands.
|
|
|
|
|
Hello ,
I am looking for an image editor control to integrate with my asp.net website project.I have tried Telerik "RadImageEditor" but it does not fulfill my needs like.
1-Control Canvas size.
2-Save image with Provided DPI
3-After Saving can edit the Saved image (like in photoshop where objects are seperate and can be edited any time after) if this is not possible then it should have selection option so that i can select any part of image and can edit it.
can u pls suggest me some controls that can itegrate with asp.net website project.
|
|
|
|
|
I can suggest one thing - STOP POSTING IN MULTIPLE FORUMS !!!
pick the best forum that you think fits, and post there, ONCE
|
|
|
|
|
I once heard that one of the advantages of PNG (over jpg eg.) is that when used on a webpage the image comes through in "blocks" making the site more responsive, while jpg had to be loaded in "one go".
Did I dream this or is this really so?
(I could only find things like transparancy, better for logo's etc... where jpg is better for real photos)
thanks.
|
|
|
|
|
I thought it was the other way round. You can use progressive jpg where the image starts blocky and is rendered in increasing detail as the rest arrives.
PNG does have a rep for being better for 'geometric' stuff as opposed to photos.
hth
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
That's not quite right. You can have an interlaced JPG just as easily as you can have a progressive PNG. Where PNG has the advantage is if you save it as progressive. Progressive PNGs use a two dimensional interlace, which results in it doing 7 passes, instead of 4 passes - which means that you see something within 1/64 of the time you would see the whole item.
It's worth being aware that no matter which option you choose, you would end up increasing the size of the none progressive/interlaced image.
|
|
|
|
|
not quite true.
progressive JPG (an uncommon but perfectly legal variation) allows for JPGs to be transferred in a series of images, each with higher resolution. the final image gets sharper as you go.
interlaced PNG allows you to transfer pixels out of the standard order - they are transferred in a fixed pattern that's basically an ever-finer grid. the receiver would just the duplicate pixels it has received until all have been transferred.
any speedup depends entirely on the reader being smart enough to display the images progressively.
|
|
|
|
|
Hi all,
4 points are defined as follows:
float[,] ctrlpoints = new float [4,3] {{ -4.0f, -4.0f, 0.0f }, { -2.0f, 4.0f, 0.0f }, { 2.0f, -4.0f, 0.0f }, { 4.0f, 4.0f, 0.0f }};
When the 4 points are called in following method:
private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
{
OpenGL gl = openGLControl.OpenGL;
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
int i;
gl.Color(1.0f, 1.0f, 1.0f);
gl.Begin(OpenGL.GL_LINE_STRIP);
for (i = 0; i <= 30; i++)
{
gl.EvalCoord1((float)i / 30.0);
}
gl.End();
gl.PointSize(5.0f);
gl.Color(1.0f, 1.0f, 0.0f);
gl.Begin(OpenGL.GL_POINTS);
for (i = 0; i < 4; i++)
{
gl.Vertex(&ctrlpoints[i][0]);
}
gl.End();
gl.Flush();
}
The &ctrlpoints[i][0] in gl.Vertex(&ctrlpoints[i][0]) was displayed to be an error.
How to fix the problem? Thanks!
|
|
|
|
|
Which language are you using? Most of your syntax looks like C#, but &ctrlpoints[i][0] looks like C++ (or possibly C# in an unsafe context).
If it's C#, what's the signature of the Vertex method in the Object Browser?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
pvpeng wrote: was displayed to be an error. What error; please do not expect people to guess what messages you are seeing. I cannot find a description for either a Vertex function, or class constructor; is this something you have created yourself?
|
|
|
|
|
|
I am working in C++. I am trying to draw a perpendicular hash mark from the start of a sloped line. My code below draws a perpendicular line but when the slope of the original line changes the hash mark appears to change length. When the line is close to horizontal the hash mark looks longest and shortest when the line is close to vertical. I believe the problem is the fixed value for HashLength. Can you show a better way to calculate the end of the perpendicular line(px2,py2) so my hash mark always looks the same size.
Orig_Line_Slope = (y1-y2)/(x1-x2);
Recipical_Slope = ((1.0 / Orig_Line_Slope)*-1);
HashLength = 10.0;
px2 = (x1+HashLength);
py2 = (y1+(Orig_Line_Slope*HashLength));
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, px2, py2 );
|
|
|
|
|
//Denote change in x =dx
//Denote change in y =dy
float dx=0.0;
float dy=0.0;
//Then dx^2 + dy^2 = HashLength ^2 ..eq 1
//We can express dy in terms of dy because
// dy/dx= Recipical_Slope
// simplifying..
// dy=Recipical_Slope*dx
//Replacing dy in eq 1, we have
//dx^2 + (Recipical_Slope *dx)^2= HashLength^2
//simplifying..
dx=sqrt(HashLength^2/(1+Recipical_Slope^2));
dy=Recipical_Slope * dx;
px2=x1+dx;
py2=y1+dy;
|
|
|
|
|
To Yang Kok Wah
I tested your solution and it works very well.
Thank You
|
|
|
|
|
Dear All,
I am a starter in OpenGL and SharpGL. I am using C# and SharpGL. However, I do not know how to write glutSwapBuffers() in OpenGL to SharpGL format.
Thanks in advance.
|
|
|
|
|
I am using SharpGL to add a solid object to a scene by clicking a button.
private void InitElements(Scene scene)
{
var objectRoot = new SharpGL.SceneGraph.Primitives.Folder() { Name = "Root" };
scene.SceneContainer.AddChild(objectRoot);
// This implements free rotation(with translation and rotation).
var camera = GetCamera();
float cmX = camera.Position.X; float cmY = camera.Position.Y; float cmZ = camera.Position.Z;
float tgX = camera.Target.X; float tgY = camera.Target.Y; float tgZ = camera.Target.Z;
float upX = camera.UpVector.X; float upY = camera.UpVector.Y; float upZ = camera.UpVector.Z;
objectArcBallEffect = new ArcBallEffect(cmX, cmY, cmZ, tgX, tgY, tgZ, upX, upY, upZ);
objectRoot.AddEffect(objectArcBallEffect);
var axisRoot = new SharpGL.SceneGraph.Primitives.Folder() { Name = "axis root" };
scene.SceneContainer.AddChild(axisRoot);
axisArcBallEffect = new ArcBallEffect(cmX, cmY, cmZ, tgX, tgY, tgZ, upX, upY, upZ);
axisRoot.AddEffect(axisArcBallEffect);
InitLight(objectRoot);
InitAxis(objectRoot);
InitAxis(axisRoot);
InitFrameElement(6, 24, 7, objectRoot);
}
After I initiate the solid elements in scene, I would like to add a solid object to that scene by clicking a button. I successfully add it in scene. But I cannot drag and rotate it with the initial elements in the scene. It means I didn't successfully add it to the same scene. Thanks in advance.
private void btnAddEllement_Click(object sender, EventArgs e)
{
var objectRoot = new SharpGL.SceneGraph.Primitives.Folder() { Name = "Root" };
var scene = this.sceneControl1.Scene;
addCylinder(objectRoot, 50, 30, 100, 5);
scene.SceneContainer.AddChild(objectRoot);
}
|
|
|
|
|
|
Hi,
When I printed a text on screen, I saw the text height equal to "tmHeight- tmInternalLeading".
For example: I printed a text size "8" on screen, I got the actual text height "tmHeight - tmInternalLeading" which is less than "8".
I printed a letter of "H" which height is less than "8", when I used "Arial" true type font of size "8".
Is there a way to make a actual text height (on screen) (ascent) equal to "8"?
Best,
-- modified 12-Jun-14 15:38pm.
|
|
|
|
|
8 points, 8 pixel, 8em? And where?
transoft wrote: Is there a way to make a actual text height (on screen) (ascent) equal to "8"? Yes, by setting the font-size. Do keep in mind that different characters have different heights', unless you're using a monospace font like courier.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for reply.
Maybe I did not make clear.
I set font size to be 8 unit which should be printed on screen to be (suppose) 100. But I got 90 (letter height) which equals to ascent.
It looks like font size is defined to be equal to "ascent + InternalLeading".
My question is: Is there a way to let (letter height) to be "ascent + InternalLeading".
|
|
|
|
|
transoft wrote: Maybe I did not make clear.
True. Which "unit"? A pixel can be a unit, a centimeter can be one.
Printed on screen? On a form as a label? Drawed as a bitmap?
transoft wrote: It looks like font size is defined to be equal to "ascent + InternalLeading". Where did you get that information? The font size is usually set by specifying the size property, as shown here[^]. Can you post some code that explains what you're doing?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The information -- is correct. There is internal leading (rhymes with sledding) and external leading. They are there to pad the character within its space and to provide space between lines for things like ascenders and descenders, which exceed the character's space.
|
|
|
|
|
I am using C++ and GDI+. I am drawing 2D diagrams. I am using the standard lines, ellipse, rotation transformations and Fonts. I need to scale the print so the screen image fills a single page. I need to avoid pixilation, the print should retain the curved lines and curves in the font. The GDI+ print tutorials I am finding are very basic. Can someone point me to a GDI+ printing tutorial that shows this type of scaled printing.
Thanks
Larry
|
|
|
|
|