Horizontal text positioning of DrawString method

I am trying to reproduce the below XPS XAML using the GDI+:
<FixedPage xmlns="http://schemas.microsoft.com/xps/2005/06" xmlns:x="http://schemas.microsoft.com/xps/2005/06/resourcedictionary-key"
xml:lang="und" Width="816" Height="1056">
<Path Fill="#FFFFFFFF" Data="M0,0L816,0 816,1056 0,1056Z" />
<Canvas Clip="M0,0L816,0 816,1056 0,1056Z">
<Path Fill="#FFFFFFFF" Data="M0,0L816,0 816,1056 0,1056Z" />
<Path Fill="#FF008000" Data="M0,0L816,0 816,1056 0,1056Z" />
<Canvas RenderTransform="1,0,0,1,10,10">
<Path Fill="#FFFFFF00" Data="M0,0L796,0 796,120 0,120Z" />
<Canvas Clip="M0,0L796,0 796,120 0,120Z">
<Glyphs OriginX="0" OriginY="87.5866666666667" FontRenderingEmSize="96" FontUri="/Resources/1057478c-ad6c-46da-af29-3e00c349c111.ODTTF" UnicodeString="Rutger
Koperdraad" Fill="#FF000000" xml:lang="en-us" />
</Canvas>
</Canvas>
</Canvas>
</FixedPage>
I manage to get the rectangles and the vertical text position correctly printed to the XPS document writer using the code below:
Private Sub OnPrintPageEx(sender
As Object, e
As PrintPageEventArgs)
If m_intPageNumber < m_objPaginator.PageCount
Then
Using objGraphics
As System.Drawing.Graphics = e.Graphics
' Correction factor between WPF and printer units
Dim f As
Single = 100 / 96
' Set the graphics quality
objGraphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.None
objGraphics.InterpolationMode = Drawing.Drawing2D.InterpolationMode.NearestNeighbor
' Draw the green background
Dim stcRect1 As
New Drawing.RectangleF(0, 0, 816 * f, 1056 * f)
Call objGraphics.FillRectangle(Drawing.Brushes.DarkGreen, stcRect1)
' Draw the yellow rectangle
Dim stcRect2 As
New Drawing.RectangleF(0, 0, 796 * f, 120 * f)
Call objGraphics.TranslateTransform(10 * f, 10 * f)
Call objGraphics.FillRectangle(Drawing.Brushes.Yellow, stcRect2)
' Draw the text
Dim objFont As
New Drawing.Font("Times New Roman", 72)
Dim intEmHeight As
Integer = objFont.FontFamily.GetEmHeight(objFont.Style)
Dim intCellAscent
As Integer = objFont.FontFamily.GetCellAscent(objFont.Style)
Dim sngOffset As
Single = 87.58667F - 96.0F / intEmHeight * intCellAscent
Dim stcRect3 As
New Drawing.RectangleF(0, sngOffset * f, 796 * f, 120 * f)
Call stcRect3.Inflate(100 / 96, 100 / 96)
Call objGraphics.DrawString("Rutger Koperdraad", objFont, Drawing.Brushes.Black, stcRect3)
End Using
m_intPageNumber += 1
e.HasMorePages = (m_intPageNumber < m_objPaginator.PageCount)
End If
End Sub
However, the horizontal text positioning is still different. The first letter starts too far to the right and the overall text is wider. How can I reproduce the XAML correctly in the GDI+?
To give some background: I have a WPF application that can print using WPF/XPS technology. Since this print path gives quality problems on many legacy printer driver (bad image resolution due to a bug in the XPS to GDI+ conversion), I am building an
alternative print engine based on the GDI+. So effectively, I need to convert my WPF graphics to the GDI+.
Rutger Koperdraad.

OK, I found the answer myself. By adding the string format as below, I get the correct result.
' Draw the text
Dim objFont As
New Drawing.Font("Times New Roman", 72)
Dim intEmHeight As
Integer = objFont.FontFamily.GetEmHeight(objFont.Style)
Dim intCellAscent
As Integer = objFont.FontFamily.GetCellAscent(objFont.Style)
Dim sngOffset As
Single = 87.58667F - 96.0F / intEmHeight * intCellAscent
Dim stcRect3 As
New Drawing.RectangleF(0, sngOffset * f, 796 * f, 120 * f)
Dim objFormat As
New Drawing.StringFormat(Drawing.StringFormat.GenericTypographic)
Call objGraphics.DrawString("Rutger Koperdraad", objFont, Drawing.Brushes.Black, stcRect3, objFormat)
Rutger Koperdraad.
Thank you for sharing your solutions and experience here. It will be very beneficial for other community members who have similar questions.
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.

Similar Messages

  • Printing in java - text positioning

    Hi there, I need some pointers in the right direction please.
    I need to print a page out to fill in a pre-printed sheet. The data to go onto the sheet is purely numbers, but the pre-printed sheet is not in a table format (the boxes where the data goes are in seemingly random positions.)
    I am currently completing the task by laying out a panel in the way I want it and using the printComponent method, but this obviously isnt the best way to do it as all I need to print out is text.
    How is the best way to go about this? Is it possible to define the position of each line of text?
    Cheers. :)

    Well, getting the text from your JTextField should be rather easy: myJTextField.getText().
    To print it, you'll have to create an Graphics object and draw the text using the drawString method on a Graphics objects: myGraphics.drawString(myText, x, y). You will need to set the right font on the graphics before that (using the setFont() method).
    You can then use this Graphics object to print.
    See the java tutorial on printing for more info about printing: http://java.sun.com/docs/books/tutorial/2d/printing/overview.html

  • How to align text in drawstring method

    hai,
    i'm using drawString method in my application. i'm using it to draw certain data in a editorpane. in that i have to align the text content but i don't know how to align the text in it such as right alignment,left alignment and center alignment...

    JEditorPanes render text on their own, there shouldn't be any reason to call Graphics.drawString() on your own, unless perhaps you are creating custom Views.
    In any case, we cannot help you unless you post an SSCCE .

  • Getting the absolute text position from a DOM tree

    Does anybody knows how to get the absolute text position of a node inside the DOM tree? Is there any DOM implementation that keep track of the absolute text position of each Node element or I need to overload somo methods by hand?
    Regards,
    Daniel Oliveira

    The position() function in XSLT returns the order of the element.
    For an xml document with elements:
    <a>
    <b></b>
    <b></b>
    </a>
    <xsl:apply-templates select="b"/>
    <xsl:template match="b">
    Element b:
    <xsl:value-of select="position()"/>
    </xsl:template>

  • DrawString method does not understand special characters

    Hi!
    I would like to send a String to a printer. I have tried the drawString method but my problem is, that it does not understand special charaters. The newline character is not a problem as I can just use the split method and then print the resulting array of strings.
    The big problem is the tab character (\t). Is there any way to make drawString understand this character? Or is there a more simple way to print the text?
    Kind Regards,
    Mikkel

    Thanks for your replies. I have to admit that the problem was a completely different one, a really stupid one!
    The output from the print method looked horrible to say the least (it is basically an array of numbers separated by equals amounts of space). The problem was that the font was not set to be monospaced (!) so you can imagine how the output looked ;)...
    Anyway, thanks for your fast replies. I will look into that class you told about.

  • SRM - Problem with a SRM Order with text position

    Hello,
    I produced an order requisition from SRM. (Document Type EC / Field Sel.Key NBB) Unfortunately I cannot change the category of commodities during this order requisition over the transaction ME52N. This must be however possible. The appropriate Field Sel.Key NBB is correctly adjusted.
    The problem apparently lies in SRM. With normal SRM orders in the R/3 an order is put on. The category of commodities may not be changed then no more.
    With SRM orders with text positions a order requisition is to be put on in the R/3. Functions also. The category of commodities is not also here alterable only unfortunately. That must function however.
    My question: How can one change the data of the order requisition with text orders over SRM?
    Regards
    J.V.

    hi J.v
    you can make new request rather than changing the purchase request since material group in important data.
    why you want to edit the PR and again trying to edit the data in sc created from pr.
    I recommend you to create a new PR for your request.
    since
    eprofile offered sap ecc according to your material grp / purchase group combination inthe eban table (eprofile field).
    but why you are trying to edit the same pr in the backend method(it is no.2 activity in sap - not supposed to do right)
    if you dont want that request cancel the sc (complete it).
    hope now you understood.
    br
    muthu

  • JButton text position without an icon

    Hi,
    I'm trying to set the text on my JButtons to be in the top left corner. I've read many of the topics on JButton text position, but they all assume you have an icon with your text. I want to be able to do it without icons (as my buttons don't need them). I tried using the setHorizontalTextPosition and setVerticalTextPosition methods, but the text is still in the same spot.
    Does anyone have any ideas?
    Message was edited by:
    raardvark

    Hi,
    I'm trying to set the text on my JButtons to be in
    the top left corner. I've read many of the topics on
    JButton text position, but they all assume you have
    an icon with your text. I want to be able to do it
    without icons (as my buttons don't need them). I
    tried using the setHorizontalTextPosition and
    setVerticalTextPosition methods, but the text is
    still in the same spot.
    Does anyone have any ideas?
    Message was edited by:
    raardvarkPut a new border on the button that has some space on the bottom and right. Or add insets with the new border.

  • How can I make a title (text) on a postcard vertical not horizontal text?

    How can I make a title (text) on a postcard layout vertical not horizontal text?

    Insert it in a Text Box then rotate this one.
    Yvan KOENIG (VALLAURIS, France) lundi 13 juin 2011 16:20:28
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.7
    Please : Search for questions similar to your own
    before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • How to get text position in a pdf?

    I need to get text position such has width, height, x, y and base position in a pdf.
    Can one help me to work further.

    i solved PDEForm issue thank you. Now i need to get the text from PDEElement.
    Can you help for this?
      PDEElement pdeElement;
        ASInt32 numElems = PDEContentGetNumElems (pdeContent);
        ASFixedRect bBox;
        for (ASInt32 i = 0; i < numElems; i++) {
            pdeElement = PDEContentGetElem (pdeContent, i);
            if (PDEObjectGetType((PDEObject)pdeElement) == kPDEForm)
                PDEForm form = (PDEForm)pdeElement;
                PDEContent content = PDEFormGetContent(form);
                GetCoOrdinate(content);
            else if(PDEObjectGetType((PDEObject)pdeElement) == kPDEText)
                PDETextState objPDETextState;
                PDEText aotextObject;
                memset(&objPDETextState, 0,sizeof(PDETextState));
                aotextObject = (PDEText)pdeElement;
                PDETextGetTextState(aotextObject,kPDETextRun,0,&objPDETextState,sizeof (PDETextState));
                if(objPDETextState.renderMode == kPDETextInvisible)
                    AVAlertNote("Invisible");
                else
                    PDEElementGetBBox (pdeElement, &bBox);
                    os.str("");
                    os << ASFixedRoundToInt32 (bBox.top) <<":" << ASFixedRoundToInt32 (bBox.bottom) << ":" << ASFixedRoundToInt32 (bBox.left) << ":" << ASFixedRoundToInt32 (bBox.right);
                    AVAlertNote(os.str().c_str());
            else
                os.str("");
                os << "Type: "<< PDEObjectGetType((PDEObject)pdeElement);
               // AVAlertNote(os.str().c_str());
                // Get the bounding box of the PDEElement and fill out the
                // selection structure to highlight the image.
                PDEElementGetBBox (pdeElement, &bBox);
                os.str("");
                os << ASFixedRoundToInt32 (bBox.top) <<":" << ASFixedRoundToInt32 (bBox.bottom) << ":" << ASFixedRoundToInt32 (bBox.left) << ":" << ASFixedRoundToInt32 (bBox.right);
                //AVAlertNote(os.str().c_str());

  • How can I apply text position attributes (e.g. lower third) to more than one title at a time?

    How can I apply text position attributes (e.g. lower third) to more than one title at a time?

    jhb3243
    What version of Premiere Elements are you using and on what computer operating system is it running?
    In the case of this theoretical lower third to be applied to more than one title at a time
    a. Is there text in the lower third besides a graphic of some kind?
    b. Are all the titles to which this lower third is to be applied all together on the Timeline or scattered?
    If no text in lower third and titles all together, then, with text titles on Video 1 and lower third on Video 2, drag out the lower third to cover the length of the text titles on Video 1.
    I do not find "lower third" title files to be in the same category as certain effects where the Copy and "Paste Attributes" or "Paste Effects and Adjustments" lend themselves so well.
    Let us see what others have to say about all this. I will continue to experiment with what you seek and how you would prefer to get there. I am not optimistic but I will try.
    Thanks.
    ATR

  • Text positioning not correct while typing in Flex Mobile Text Area

    When I try to write text in Flex mobile TextArea, the text positioning is not correct. What might be the issue? Do I need to specify some Skin Class for it?

    Could be that the font doesn't have Hindi chars support and the text you paste is HTML chars.
    You could try to embed a font you know has the appropriate chars and use that for global and Applications CSS classes.

  • How can set direction right to left for horizontal text area

    I want set direction right to left for horizontal text area
    to view right to left String Type

    I don't know that there is such a thing as right to left
    String Type (I can't find one at least). I am assuming this
    involves some language where printed materials are read from right
    to left.
    Before I try to offer a solution though, it will be helpful
    to know more about that text area. Is the intention to type into
    the text area or to load a string into it?
    And if you are loading a string into it, is the string
    already right to left?

  • Compulsory quantity in text position of BOM

    Hi gurus,
    when I create a production order (CO01) and I add a text position in BOM (type T) the system requires an obligatory quantity. It's not logical  that a text position requires a quantity. Is it possible to make the text position not obligatory?
    Thank you.

    Its very typical scenario, looks stupid to ask quantity even when we mention the Item catagory as T, but there must be something behind this which our mand cant find out, we are unable to get that kind of scenario.
    by the way if you want to remove this files do as follows.
    Go to tranaxcation code. SE80>enter Function group CMOD> double click screen no 150>click on layout> screen painter will come. then click on filed required quantity.  the filed is "required" entry.
    change that to optional.
    It will solve your issue.  for this you need the access key, since its a change in standar SAP.
    Regards,
    Pravin Mukkawar
    TCS Gandhinagar
    SAP-PP-APO consultnat.

  • TS3274 How do I lock and unlock the vertical/horizontal screen positions?

    How do I lock and unlock the vertical/horizontal screen positions?

    Use the Side Switch or Rotation Lock in Control Center.

  • TS3274 I went to an Apple store yesterday and the guy there did something and now the ipad only works in the vertical (portrait) position and not the horizontal (landscape) position.  How can we make it work in both positions?

    I went to an Apple store yesterday and the guy there did something and now the ipad only works in the vertical (portrait) position and not the horizontal (landscape) position.  How can we make it work in both positions?

    Just in case you are not running iOS 7 and don't have the control center feature.....
    If you see a lock icon in the upper right corner of the screen - then the screen orientation is locked.
    Try the side switch above the volume rocker first and see if that unlocks the screen. If that doesn't do it and you are running iOS 5 or 6, double tap the home button and swipe to the right and look for the lock icon all the way to the left.
    If you are running iOS 7, swipe up from the bottom of the screen to get to the control center and the lock icon is in the row of icons at the top all the way to the right.
    If the screen is unlocked but still will not rotate, reset the iPad.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the button

Maybe you are looking for