Measuring of Text with Multiple Fonts in One Single Line

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.
The horizontal text positions did not appear to be correct. I reverted now to very simple text width measuring tests where the results are still puzzling.
Test 1 (GDI+): 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.
Test 2 (GDI+): 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.
Test 3 (GDI): Use of GetCharABCWidthsFloat
Attempted to create a GDI font as close as possible to the GDI+ font in the previous tests. Unfortunately, this third test shows results which do not match the previous results at all.
I am appending the full example here; the results I found during the debug session 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;
//--- 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= 44.414 ("M")
//--- Text 2 Width= 76.828 ("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 = 32.000 ("M")
RCode = RegionsList[1].GetBounds(&TextBounds1M, G); // Result: Text 1 Width = 32.000 ("M"; the second char)
RCode = RegionsList[2].GetBounds(&TextBounds2M, G); // Result: Text 2 Width = 64.000 ("MM")
//--- Test #3: using the good old GDI ----------
int MapModeResult = SetMapMode(hDC, MM_TEXT); // MM_TEXT is equivalent to Unit::UnitPixel?
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); // Results: abcfA = 2.000; abcfB = 22.000; abcfC = 2.000
//--- End of Test ---
delete G;
Does anybody have an idea why I get so different results?
Thanks in advance.

This is a development question and should be directed to a forum that assists in coding. The forum you posted to is for Windows 7 related questions.
Sorry I cannot help you
Don't forget to mark the post that solved your issue as "Answered." By marking the Answer you are enabling users with similar issues to find what helped you. Lewis Renwick - IT Professional

Similar Messages

  • IDOC with Multiple Segment to One Single Record Mapping

    Hello
    I have a problem mapping the values of the segment <E1CSKTM>
    which occurs two times in my source IDOC to a single record.
    My requirement is to get one field (LTEXT) from the first E1CSKTM segment and map it to Name and take the same field (LTEXT) but from the second E1CSKTM segment and map it to OrgDescription
    The source message:
    <?xml version="1.0" encoding="UTF-8"?>
    <COSMAS01>
       <IDOC BEGIN="1">
          <EDI_DC40 SEGMENT="1">
             <TABNAM>EDI_DC40</TABNAM>
             <MANDT>300</MANDT>
             <DOCNUM>0000000000750131</DOCNUM>
             <DOCREL>700</DOCREL>
             <STATUS>30</STATUS>
             <DIRECT>1</DIRECT>
             <OUTMOD>2</OUTMOD>
             <IDOCTYP>COSMAS01</IDOCTYP>
             <MESTYP>COSMAS</MESTYP>
             <STDMES>COSMAS</STDMES>
             <SNDPOR>SAPQAE</SNDPOR>
             <SNDPRT>LS</SNDPRT>
             <SNDPRN>QAE300</SNDPRN>
             <RCVPOR>SAPQAX</RCVPOR>
             <RCVPRT>LS</RCVPRT>
             <RCVPRN>QAX304</RCVPRN>
             <CREDAT>20080308</CREDAT>
             <CRETIM>090820</CRETIM>
             <SERIAL>20080211134325</SERIAL>
          </EDI_DC40>
          <E1CSKSM SEGMENT="1">
             <MSGFN>005</MSGFN>
             <MANDT>300</MANDT>
             <KOKRS>1000</KOKRS>
             <KOSTL>0105012501</KOSTL>
             <DATBI>99991231</DATBI>
             <DATAB>19000101</DATAB>
             <ERSDA>20060219</ERSDA>
             <USNAM>HAMEED</USNAM>
             <BKZER>X</BKZER>
             <BKZOB>X</BKZOB>
             <PKZER>X</PKZER>
             <MGEFL>X</MGEFL>
             <BUKRS>1000</BUKRS>
             <GSBER>20</GSBER>
             <KOSAR>N</KOSAR>
             <VERAK>TBA</VERAK>
             <WAERS>SAR</WAERS>
             <KHINR>105012001</KHINR>
             <KOMPL>X</KOMPL>
             <OBJNR>KS10000105012501</OBJNR>
             <PRCTR>0105012000</PRCTR>
             <FUNC_AREA>Z240</FUNC_AREA>
             <FUNC_AREA_LONG>Z240</FUNC_AREA_LONG>
             <E1CSKTM SEGMENT="1">
                <MSGFN>005</MSGFN>
                <SPRAS>A</SPRAS>
                <KTEXT>&#1605;&#1583;&#1610;&#1585; &#1575;&#1604;&#1583;&#1575;&#1574;&#1585;&#1577; &#1608;&#1605;&#1608;&#1592;&#1601;&#1608;&#1607;</KTEXT>
                <LTEXT>&#1605;. &#1583;. &#1608;&#1605;&#1608;&#1592;&#1601;&#1608;&#1607;/ &#1581;&#1587;&#1575;&#1576;&#1575;&#1578; &#1605;&#1606;&#1591;&#1602;&#1577; &#1575;&#1604;&#1605;&#1583;&#1610;&#1606;&#1577;</LTEXT>
                <SPRAS_ISO>AR</SPRAS_ISO>
             </E1CSKTM>
             <E1CSKTM SEGMENT="1">
                <MSGFN>005</MSGFN>
                <SPRAS>E</SPRAS>
                <KTEXT>DvM and Stff/AOD-Mad.</KTEXT>
                <LTEXT>Div Mgr and Staff/AOD-Madinah</LTEXT>
                <SPRAS_ISO>EN</SPRAS_ISO>
             </E1CSKTM>
          </E1CSKSM>
       </IDOC>
    </COSMAS01>
    The Target Message:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:CostElementMT xmlns:ns0="http://se.com.sa/materials">
       <INSERT>
          <COSTELEMENT_DATA action="INSERT">
             <TABLE>usmuser.OrganizationCodes_test</TABLE>
             <access>
                <OrgCode>105012001</OrgCode>
                <CostCenter>0105012501</CostCenter>
                <OrgDescription> English Name<OrgDescription/>
                <Name>Arabic Name</Name>
             </access>
          </COSTELEMENT_DATA>
       </INSERT>
    </ns0:CostElementMT>
    is this possible using the graphical mapping?

    Hi Baheej,
    If in your input "E1CSKTM" segment always occurs twice than u can go with the above UDF mentioned by Chirag and also u need to take care that field (LTEXT) also always occurs.If the field does not occur always than you need to check it using exists functions.
    Andmoreover if the "E1CSKTM" segment does occur more than twice than u need to create a UDF where u need to pass the values alternatively.
    Please check the above details and let us know if any furthur enhancements are to be made.
    Thanks,
    Bhargav
    Note:Award Points if found useful.

  • [svn:fx-trunk] 8531: If using an embedded font, need to measure the text with it so that if auto-sizing, the correct amount of space is allocated.

    Revision: 8531
    Author:   [email protected]
    Date:     2009-07-13 12:25:57 -0700 (Mon, 13 Jul 2009)
    Log Message:
    If using an embedded font, need to measure the text with it so that if auto-sizing, the correct amount of space is allocated.
    QA Notes:
    Doc Notes: SDK-22205.
    Reviewers: will be Gordon
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-22205
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/primitives/RichEditableText.as

    Revision: 8531
    Author:   [email protected]
    Date:     2009-07-13 12:25:57 -0700 (Mon, 13 Jul 2009)
    Log Message:
    If using an embedded font, need to measure the text with it so that if auto-sizing, the correct amount of space is allocated.
    QA Notes:
    Doc Notes: SDK-22205.
    Reviewers: will be Gordon
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-22205
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/primitives/RichEditableText.as

  • I want to validate multiple input type=text with spry validation any one hepl me?

    I want to validate multiple input type=text with spry validation any one hepl me?
    my code is as below plz help me
               *Professional Experience             Years        Months                             

    Read;
    http://labs.adobe.com/technologies/spry/articles/textfield_overview/index.html
    http://labs.adobe.com/technologies/spry/widgets/textfieldvalidation/SpryValidationTextFiel d.html
    and check out the samples:
    http://labs.adobe.com/technologies/spry/samples/

  • Printing Text with multiple Lines

    Hello,
    i want to print a list and in that is text with multiple lines.
    In the PrintPreview and in the Printout i get only one line.
    How is the best way to do this?
    Thank you,
    Markus
    Private Function Print_Remarks_Control_Get(ByVal pstrText As String) As TextBox
    Dim TextBox_Out As New TextBox
    With TextBox_Out
    .Text = pstrText
    .HorizontalAlignment = Xaml.HorizontalAlignment.Left
    .VerticalAlignment = Xaml.VerticalAlignment.Top
    .FontSize = 16
    .Margin = New Thickness(15)
    .AcceptsReturn = True
    .MinWidth = 800
    .MinHeight = 600
    End With
    Return TextBox_Out
    End Function
    Sub PrintPageList_Prepare()
    Dim i As Integer
    Dim objVM As clsTextVM
    Dim lstText_List As ObservableCollection(Of clsText)
    Dim ctrPrint_StackPanel As StackPanel
    Dim ctrPrint_Title As TextBox
    Dim ctrPrint_Description As TextBox
    Dim ctrPrint_Remarks As TextBox
    Dim objText As clsText
    mPrintPageList.Clear()
    objVM = DirectCast(Me.DataContext, clsTextVM)
    lstText_List = objVM.CustomClass_List
    ctrPrint_StackPanel = Print_StackPanel_Get()
    For i = 0 To lstText_List.Count - 1
    objText = lstText_List.Item(i)
    If objText.Name.Length > 0 Then
    ctrPrint_Title = Print_Title_Control_Get(objText.Name)
    ctrPrint_StackPanel.Children.Add(ctrPrint_Title)
    End If
    If objText.Description.Length > 0 Then
    ctrPrint_Description = Print_Description_Control_Get(objText.Description)
    ctrPrint_StackPanel.Children.Add(ctrPrint_Description)
    End If
    If objText.Remarks.Length > 0 Then
    ctrPrint_Remarks = Print_Description_Control_Get(objText.Remarks)
    ctrPrint_StackPanel.Children.Add(ctrPrint_Remarks)
    End If
    Next
    mPrintPageList.Add(ctrPrint_StackPanel)
    End Sub
    Private Sub OnGetPreviewPage(sender As Object, e As GetPreviewPageEventArgs)
    ' Das ist die MessageBox
    ' Windows.UI.Popups.MessageDialog()
    PrintPageList_Prepare()
    mPrintDok.SetPreviewPage(e.PageNumber, Me.mPrintPageList(e.PageNumber - 1))
    End Sub

    Yes, not only RichEditBox but also RichTextBlock can also do this. Besides TextBox also have TextWrapping functionality.
    -James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • HP Officejet 6500A How do I scan a document with multiple pages into one file?

    HP Officejet 6500A Plus e-All-in-One Printer - E710n
    Windows 7 (64 bit)
    How do I scan a document with multiple pages into one file?  My old printer (psc 2110) asked after each scan if I wanted to scan another page.  At the end I had one pdf file with multiple pages.
    This new one creates one file for each page and I cannot find a way to create one pdf file with multiple pages.
    This question was solved.
    View Solution.

    Hi mpw101,
    If you load the papers into the ADF - Automatic Document Feeder, and then select Document to PDF then they will all be scanning into one file. Let me know if this works for you?
    I am an HP employee.
    Say Thanks by clicking the Kudos Star in the post that helped you.
    Please mark the post that solves your problem as "Accepted Solution"

  • Copy text from multiple fields to one field

    I would like to copy text from multiple fields into one field. Each of these smaller fields will only be allowed to have one character. The larger field will not be able to be edited.
    So far, I have thought of creating a naming heirarchy for these fields. I was going to then call upon the array of the parent and set the value of the parent to equal this array.
    var parent = this.getField("everything");
    var array = everything.getArray();
    var v;
    for(parent=0; parent<array.length; parent++)
    v = a + " " + v;               //Im guessing this line is incorrect
    parent.value = a;
    Any suggestions? or a better way of doing this.
    Thanks

    The code sample you provided is using AcroForm scripting and will not work in this form. There is another post similar to this one...have a look at this one it might help you out. It is doing the opposite of what you want but the concept of the loop and how each field is addressed inside ofthe loop is what you wil need.
    http://forums.adobe.com/message/2954517#2954517
    Paul

  • How to edit a text with same font in a image in photoshop 7

    how to edit a text with same font in a image in photoshop 7

    Good day!
    The question seems to provide insufficient information for a relevant answer.
    Do you have the font?
    Is the text a (Type) Layer of its own or part of the image?
    Could you please post a screenshot with the Layers Panel visible?
    Regards,
    Pfaffenbichler

  • Problems with multiple idocs in one file ( Inbound file )

    HI,
    Thanks in Advance for your suggestions.. Highly appreciated.
    We have problems with multiple IDocs in one file.
    We are using XIB ( Amtrix ) as Middleware to receive the files.
    Curretenly When the file contains one IDoc then there is no problem. IDoc is created and everything is ok.
    If file contains two IDocs ( for example two messages ORDERS and DELVERY ) then it is creating two IDocs but both IDocs contains ORDERS plus DELIVERY segements information. That is the problem. Some how SAP unable to differentiate the IDocs in the file.. But it knows that how many idocs are there in the file..because it is creating exact number of idocs.
    We are using TRFC port ... Do I need to change it to File port..
    When we have more than one idoc do we need set any parameter in the file ...

    Thanks for the swift response. Always ideas are useful.
    As of now , Middleware cannot split the file.
    Thing is SAP is creating two Idocs with different message types. Problem is First IDoc contains ORDERS message type but also DELIVERY segments as well. Second IDoc with DELIVERY message tyoe but ORDERS segments as well... This is the problem... I think we are missing some field activation in file for EDIDC record.
    As far as I know file port supports the number of IDocs in one file.. Hope TRFC port also supports that

  • Concatenate multiple records into one single record

    Hello everyone,
    Can anyone guide me how to merge multiple records into one single record
    like......... I am getting the data in the file like
    aaaaa/bbbbbbb/ccccccccccc/dddddddddddd/eee
    ffffff/gggg/hhhhhhhhhhhhhh
    /123/4567/55555/99999999/kaoabfa/eee
    fffff/kkkkkkkk/llllllllllllllllllllllll
    when i use gui_upload I am getting the data into the internal table in the above format.
    My main intension is to split the record at / to multiple lines and dowload it into another file.
    What i am planning to do is... if the line does not start with / then i want to concatenate the multiple lines into single line and then split it into multiple records. Can anyone guide me how to achieve this.

    Yes, it should work.
    In my example
    Loop at itab.
    concatenate i_text itab into i_text.
    endloop.
    You change that loop for the loop of your internal table with the file records
    So if you have this three records
    'aaaa/bbb/ccc'
    '/dddd/efg'
    'hijk/lmn'
    i_text will look like this at the end
    'aaaa/bbb/ccc/dddd/efghijk/lmn'
    then in this part of the code
    split i_text at '/' into table itab2.
    itab2 will have the records looking like this
    aaaa
    bbb
    ccc
    dddd
    efghijk
    lmn'

  • Multiple Reports inside one Single Report

    Post Author: maximus85
    CA Forum: Crystal Reports
    Hi....I'm having this problem of having multiple reports inside one single report. Basically what i wanted to built is a Dashboard that contains 4 main subjects:i)Sales   -    Contains graph that can be drill down for further detailsii)Internal Process   -  Contains tables that can be drill downiii)Profit/Lossiv)HRAs far as i know, since all four are of different fact table data, they cannot be all thrown inside one single report to be built on. So i came out with using subreports instead for each components and then finally putting them all together as subreport inside the main report(Dashboard).However, i just realized that by doing that, whenever i clicked on the reports that i wanted to drill down with, it will prompt that particular report that i clicked into a new page, and then from there only i can perform drill down.Is there anyway to enable me to straight away drill down the Sales and Internal Process reports from the main reports(Dashboard) instead of having to click twice as that will be unnecessary right?Or mayb if there's another better ways to do what I have to do? Please do advise and suggest......Thanks alot.......

    hi chack,
    doesnt matter or preferrably both, as long as i can export all the reports in 1 page into 1 excel, or 1 pdf.

  • Issues with multiple Files with multiple subdbs on a single environment.

    I'm having an issue with Berkeley DB 4.2 on 32-bit platforms, regarding multiple physical files with multiple subdatabases in a single database environment. Specifically, when I open a subdatabase for a physical file, Berkeley DB thinks that it is using the same subdatabase in a different physical file.
    I'm doing the following:
    1. Create and open a db enviornment.
    2. Move file1 to the common area.
    3. Open, get and close the subdatabases in file1.
    4. Move file2 to the common area.
    5. Open, get and close the subdatabases in file2.
    6. remove file2 from the common area
    7. Move file3 to the common area.
    8. Open a subdatabase from file3. About 1/2 the time, the fetches
    return data from file2, not from file3.
    It's possible that at some earlier time (i.e. before step 1 of this
    test case), file1, file2 and file3 were the same file. I noticed
    that there is something called env->fileid_reset, but that is not
    in 4.2.52.
    Any ideas?

    Looks like I've resolved the issue

  • MessageTransformBean - SimplePlain2XML - Multiple records on a single line

    Hi,
    I am trying to convert multiple record from a single line to multipe rows in an XML message with the MessageTransformBean.
    If the record look like this it's working:
    RECORD1textETC
    RECORD2textETC
    But the incoming message are all on a single line:
    RECORD1textETCRECORD2textETC
    Is there a way to add a linefeed to my incoming message after X characters, or to tell the adapter to split by length instead of spliting on the end of line?
    Thanks,
    Martin

    I had to code a custom Module Adapter to do it.
    Here's the main part of the module adapter EOLConvertBean...
    Message msg = (Message) inputModuleData.getPrincipalData();
    XMLPayload xmlpayload = msg.getDocument();
    byte[] content = xmlpayload.getContent();
    byte crlf = 0x0A; // end of line char
    int current = 0;  // current bytes read     
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int lines = content.length / recordLen; // record len = insert EOL after X recordLen
    // TODO change for do while for 1x line record
    for (int i = 0; i <= lines; i++) {
         baos.write(content, current, recordLen);
         baos.write(crlf);
         current += recordLen;
    xmlpayload.setContent(baos.toByteArray());
    inputModuleData.setPrincipalData(msg);
    Edited by: Martin Lavoie Rousseau on Oct 6, 2010 9:08 PM

  • Can I add multiple elements on a single line?

    Can I add multiple elements on a single line?

    Not yet. But this is something we plan to support. You can vote on this idea here: http://forums.adobe.com/ideas/1046
    We use this to help prioritize our work.
    Randy

  • Safari rendering default text with condensed font?

    Has anyone else experienced this in the last few days?
    All of a sudden Safari is rendering default text with a different font, a light, condensed one.
    The side-by-side shows the Wordpress Admin menu on my Macbook & on my iMac.
    The Macbook is still rendering as always, the iMac now has this new font.
    Aside from within the Wordpress Admin area, I'm seeing the same thing in various other places you'd expect to see a default font, for default text.
    It's not the end of the world but considering I haven't done anything to cause the change I'm concerned it's something malicious causing it,
    any insights anyone?
    Thanks in advance.

    Installled any third party fonts lately?
    And check for duplicate fonts.
    Open the Font Book in your Applications folder.
    From the Font Book menu bar click Edit > Look for Enabled Duplicates

Maybe you are looking for

  • The action cannot be completed. the connection to microsoft exchange is unavailable

    Hi dear. We have exchange 2013 and we want auto configure outlook 2007,2010 and 2013. In first time when we are setup exchange 2013 we can auto  configure outlook. But I don't know now we cannot configure outlook. I think when we make some change in

  • Looking for app to show itunes

    Is their an app that will show what song is playing and allow me to control itunes while I am browsing the web.

  • Export text files

    Hi I need to export text files delimited by '|', but our data is very large, i want to know if i can use some database utility. would you help me with this problem ? Felix Ramirez.

  • SAP C4C(Cloud for Customer)

    Hi, I am SAP CRM consultant, i am very much interested in SAP cloud for Customer Can anybody suggest me SAP C4C Career Path ? Regards, Nawed

  • Problems with Flash pluggin

    I am running Windows XP with IE 6. I have been using this system to listen to my favorite radio station for years and now suddenly I get a message that I need to load Flash Pluggin 6 or higher to beable to connect. Not sure what has changed but I hav