Gdiplus::PointF originPt(fXPen + i_originOffset.h, fYPen + i_originOffset.v - GetFontAscent()) Gdiplus::Color argb(255,GetRValue(fForeColor),GetGValue(fForeColor),GetBValue(fForeColor)) Gdiplus::StringFormat strFormat(Gdiplus::StringFormatFlagsMeasureTrailingSpaces) Gdiplus::Font gdiFont(GetDC()) SetFontHint(destContext, gdiFont) The resulting code is quite acceptable and always correct. What I do is write the text as red on blue, which means that I only have to check one byte. This requires some knowledge of bitmaps and colors. GetPixel is terribly slow, but.you can lock the bits, and check the bitmap directly as an array of bytes. you can then check the bits yourself, and be right every time. I did many hours of similar work to try and find that magic bullet, but.I finally decided to create my own measurement system that works in all cases. Fonts really belong to that driver, Windows simply manages them. Rasterizer exists in your display device driver, not in Windows. The thing is that GDI must guess at what the rasterizer is going to do, and the Then, there is the issue of kerning, which complicates matters sometimes. Text due to overhang is an example of something that is inconsistent across different hardware. It is how the display adapter interprets every aspect of drawing a string that makes it difficult to get a routine that works in all cases. ![]() There are some settings that affect that, but.the issue is not GDI+, or even GDI itself. How do i measure and draw text without this crazy padding? Is really 8 pixels wide, with 1.5 pixels on either side of padding. and "eeee" should be 48 pixels? no, it's 34. the string "ee" then should be 24 pixels wide, right? but no, it's 19. Note i've also actually measured some strings:Īt font size 15, the letter "e" is 12 pixels wide. and yes i'm quite sure there are no actual spaces. i've drawn the extent rects to hilight this. but there is extra space around every portion. ![]() In this example, look at the word "believe" in the first line, it is split into 3. i looked for a flag that says "don't pad" but there isn't one. To draw a single word split in half, using two calls. Also, when i draw the text, it pads the start with space, so the text does not start at exactly the left pixel edge. When i use GDI+ MeasureText(), it returns the width of the text plus some padding on either end.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |