Skip to content

wxgetscreentextextent problem

Forums Forums SIMPOL Programming wxgetscreentextextent problem

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #328
    Jean Vallee
    Participant

    Been trying to use wxgetscreentextextent to print white text on black background. However, the width in pixel returned by it is not correct. Putting ruler to paper, it’s telling me the text will be 3.11″ wide when it’s actually only 2.25″ (approx). Makes it print extra black “space” at end of text. wxfont revfonthead revfonthead =@ wxfont.new(“Tahoma”,14,”n”,”b”,””, error = e) wxgetscreentextextent(revfonthead, “RESIDENTIAL CONSTRUCTION”, width = tw, height = th) // tw is now 299 – way too big – should be about 216 or so… integer mtw mtw = tw/app.form.currentdpi * 25400 ;// to convert to mm // then I use mtw to specify a printwidth on a printform1 Any ideas on how to make it more accurate? Jean Vallee

    #1589
    Michael
    Keymaster

    On 22/04/2013 19:43, Jean Vallee wrote:
    > Been trying to use wxgetscreentextextent to print white text on black
    > background.
    > However, the width in pixel returned by it is not correct. Putting ruler
    > to paper, it's telling me the text will be 3.11" wide when it's actually
    > only 2.25" (approx).
    > Makes it print extra black "space" at end of text.

    Hi Jean,

    This function is not tuned to use printer fonts. It can only reliably tell you how much space is required to display the text in
    pixels.

    > wxfont revfonthead
    > revfonthead =@ wxfont.new("Tahoma",14,"n","b","", error = e)
    > wxgetscreentextextent(revfonthead, "RESIDENTIAL CONSTRUCTION", width = tw,
    > height = th)
    >
    > // tw is now 299 – way too big – should be about 216 or so…
    >
    > integer mtw
    > mtw = tw/app.form.currentdpi * 25400 ;// to convert to mm
    >
    > // then I use mtw to specify a printwidth on a printform1
    >
    > Any ideas on how to make it more accurate?

    The result is the value in pixels. Any conversion assumes a direct relationship with a printout, which is not the case.

    Ciao, Neil

    #2229
    Jean Vallee
    Participant

    On 4/29/2013 1:39 PM, Neil Robinson wrote:
    > On 22/04/2013 19:43, Jean Vallee wrote:
    >> Been trying to use wxgetscreentextextent to print white text on black
    >> background.
    >> However, the width in pixel returned by it is not correct. Putting ruler
    >> to paper, it's telling me the text will be 3.11" wide when it's actually
    >> only 2.25" (approx).
    >> Makes it print extra black "space" at end of text.
    >
    > Hi Jean,
    >
    > This function is not tuned to use printer fonts. It can only reliably tell you how much space is required to display the text in
    > pixels.
    >
    >> wxfont revfonthead
    >> revfonthead =@ wxfont.new("Tahoma",14,"n","b","", error = e)
    >> wxgetscreentextextent(revfonthead, "RESIDENTIAL CONSTRUCTION", width = tw,
    >> height = th)
    >>
    >> // tw is now 299 – way too big – should be about 216 or so…
    >>
    >> integer mtw
    >> mtw = tw/app.form.currentdpi * 25400 ;// to convert to mm
    >>
    >> // then I use mtw to specify a printwidth on a printform1
    >>
    >> Any ideas on how to make it more accurate?
    >
    > The result is the value in pixels. Any conversion assumes a direct relationship with a printout, which is not the case.
    >
    > Ciao, Neil

    Ok so how do you estimate how much space a paragraph of text will take
    up on paper with a specified font and point size? I have many comment
    boxes that need to be printed as part of reports and they could be a
    single word, sentence or many paragraphs. I need to know if they will
    fit on the page I'm currently printing or I need to break the field and
    print what doesn't fit on the next page.

    I'm using printform1 for reports.

    Jean

    #2234
    Michael
    Keymaster

    On 29/04/2013 21:19, JV wrote:
    > On 4/29/2013 1:39 PM, Neil Robinson wrote:
    >> On 22/04/2013 19:43, Jean Vallee wrote:
    >>> Been trying to use wxgetscreentextextent to print white text on black
    >>> background.
    >>> However, the width in pixel returned by it is not correct. Putting ruler
    >>> to paper, it's telling me the text will be 3.11" wide when it's actually
    >>> only 2.25" (approx).
    >>> Makes it print extra black "space" at end of text.
    >>
    >> Hi Jean,
    >>
    >> This function is not tuned to use printer fonts. It can only reliably tell you how much space is required to display the text in
    >> pixels.
    >>
    >>> wxfont revfonthead
    >>> revfonthead =@ wxfont.new("Tahoma",14,"n","b","", error = e)
    >>> wxgetscreentextextent(revfonthead, "RESIDENTIAL CONSTRUCTION", width = tw,
    >>> height = th)
    >>>
    >>> // tw is now 299 – way too big – should be about 216 or so…
    >>>
    >>> integer mtw
    >>> mtw = tw/app.form.currentdpi * 25400 ;// to convert to mm
    >>>
    >>> // then I use mtw to specify a printwidth on a printform1
    >>>
    >>> Any ideas on how to make it more accurate?
    >>
    >> The result is the value in pixels. Any conversion assumes a direct relationship with a printout, which is not the case.
    >>
    >> Ciao, Neil
    >
    > Ok so how do you estimate how much space a paragraph of text will take
    > up on paper with a specified font and point size? I have many comment
    > boxes that need to be printed as part of reports and they could be a
    > single word, sentence or many paragraphs. I need to know if they will
    > fit on the page I'm currently printing or I need to break the field and
    > print what doesn't fit on the next page.
    >
    > I'm using printform1 for reports.
    >
    > Jean
    >

    You are trying to recreate what the graphic report engine does, although even it won't currently break a record across pages, it
    will just move it to the next page. I have an internal function that calculates the length and height of a string using the
    current Windows default printer (it is a very good idea to make sure that the default printer is the one you expect to use with
    SIMPOL). It is not a trivial piece of code.

    Ciao, Neil

    #2237
    Jean Vallee
    Participant

    On 4/30/2013 9:24 AM, Neil Robinson wrote:
    > On 29/04/2013 21:19, JV wrote:
    >> On 4/29/2013 1:39 PM, Neil Robinson wrote:
    >>> On 22/04/2013 19:43, Jean Vallee wrote:
    >>>> Been trying to use wxgetscreentextextent to print white text on black
    >>>> background.
    >>>> However, the width in pixel returned by it is not correct. Putting ruler
    >>>> to paper, it's telling me the text will be 3.11" wide when it's actually
    >>>> only 2.25" (approx).
    >>>> Makes it print extra black "space" at end of text.
    >>>
    >>> Hi Jean,
    >>>
    >>> This function is not tuned to use printer fonts. It can only reliably tell you how much space is required to display the text in
    >>> pixels.
    >>>
    >>>> wxfont revfonthead
    >>>> revfonthead =@ wxfont.new("Tahoma",14,"n","b","", error = e)
    >>>> wxgetscreentextextent(revfonthead, "RESIDENTIAL CONSTRUCTION", width = tw,
    >>>> height = th)
    >>>>
    >>>> // tw is now 299 – way too big – should be about 216 or so…
    >>>>
    >>>> integer mtw
    >>>> mtw = tw/app.form.currentdpi * 25400 ;// to convert to mm
    >>>>
    >>>> // then I use mtw to specify a printwidth on a printform1
    >>>>
    >>>> Any ideas on how to make it more accurate?
    >>>
    >>> The result is the value in pixels. Any conversion assumes a direct relationship with a printout, which is not the case.
    >>>
    >>> Ciao, Neil
    >>
    >> Ok so how do you estimate how much space a paragraph of text will take
    >> up on paper with a specified font and point size? I have many comment
    >> boxes that need to be printed as part of reports and they could be a
    >> single word, sentence or many paragraphs. I need to know if they will
    >> fit on the page I'm currently printing or I need to break the field and
    >> print what doesn't fit on the next page.
    >>
    >> I'm using printform1 for reports.
    >>
    >> Jean
    >>
    >
    > You are trying to recreate what the graphic report engine does, although even it won't currently break a record across pages, it
    > will just move it to the next page. I have an internal function that calculates the length and height of a string using the
    > current Windows default printer (it is a very good idea to make sure that the default printer is the one you expect to use with
    > SIMPOL). It is not a trivial piece of code.
    >
    > Ciao, Neil

    That is why I chose printform1 over the graphic report. It is
    conceivable that the comment field may be larger than a entire page.
    And I always know what the destination printer for reports is (stored in
    user settings table).

    So would you care to share your solution?

    Jean

    #2241
    Michael
    Keymaster

    On 30/04/2013 17:56, JV wrote:
    > On 4/30/2013 9:24 AM, Neil Robinson wrote:
    >> On 29/04/2013 21:19, JV wrote:
    >>> On 4/29/2013 1:39 PM, Neil Robinson wrote:
    >>>> On 22/04/2013 19:43, Jean Vallee wrote:
    >>>>> Been trying to use wxgetscreentextextent to print white text on black
    >>>>> background.
    >>>>> However, the width in pixel returned by it is not correct. Putting ruler
    >>>>> to paper, it's telling me the text will be 3.11" wide when it's actually
    >>>>> only 2.25" (approx).
    >>>>> Makes it print extra black "space" at end of text.
    >>>>
    >>>> Hi Jean,
    >>>>
    >>>> This function is not tuned to use printer fonts. It can only reliably tell you how much space is required to display the text in
    >>>> pixels.
    >>>>
    >>>>> wxfont revfonthead
    >>>>> revfonthead =@ wxfont.new("Tahoma",14,"n","b","", error = e)
    >>>>> wxgetscreentextextent(revfonthead, "RESIDENTIAL CONSTRUCTION", width = tw,
    >>>>> height = th)
    >>>>>
    >>>>> // tw is now 299 – way too big – should be about 216 or so…
    >>>>>
    >>>>> integer mtw
    >>>>> mtw = tw/app.form.currentdpi * 25400 ;// to convert to mm
    >>>>>
    >>>>> // then I use mtw to specify a printwidth on a printform1
    >>>>>
    >>>>> Any ideas on how to make it more accurate?
    >>>>
    >>>> The result is the value in pixels. Any conversion assumes a direct relationship with a printout, which is not the case.
    >>>>
    >>>> Ciao, Neil
    >>>
    >>> Ok so how do you estimate how much space a paragraph of text will take
    >>> up on paper with a specified font and point size? I have many comment
    >>> boxes that need to be printed as part of reports and they could be a
    >>> single word, sentence or many paragraphs. I need to know if they will
    >>> fit on the page I'm currently printing or I need to break the field and
    >>> print what doesn't fit on the next page.
    >>>
    >>> I'm using printform1 for reports.
    >>>
    >>> Jean
    >>>
    >>
    >> You are trying to recreate what the graphic report engine does, although even it won't currently break a record across pages, it
    >> will just move it to the next page. I have an internal function that calculates the length and height of a string using the
    >> current Windows default printer (it is a very good idea to make sure that the default printer is the one you expect to use with
    >> SIMPOL). It is not a trivial piece of code.
    >>
    >> Ciao, Neil
    >
    > That is why I chose printform1 over the graphic report. It is
    > conceivable that the comment field may be larger than a entire page.
    > And I always know what the destination printer for reports is (stored in
    > user settings table).
    >
    > So would you care to share your solution?
    >
    > Jean
    >

    I have had a brief look, but it will take a bit of surgery to extract the code from the graphicreport library, since this is a
    member function of a graphicreport1 object. I will see what I can do.

    Ciao, Neil

    #2248
    Jean Vallee
    Participant

    On 5/2/2013 1:20 PM, Neil Robinson wrote:
    > On 30/04/2013 17:56, JV wrote:
    >> On 4/30/2013 9:24 AM, Neil Robinson wrote:
    >>> On 29/04/2013 21:19, JV wrote:
    >>>> On 4/29/2013 1:39 PM, Neil Robinson wrote:
    >>>>> On 22/04/2013 19:43, Jean Vallee wrote:
    >>>>>> Been trying to use wxgetscreentextextent to print white text on black
    >>>>>> background.
    >>>>>> However, the width in pixel returned by it is not correct. Putting ruler
    >>>>>> to paper, it's telling me the text will be 3.11" wide when it's actually
    >>>>>> only 2.25" (approx).
    >>>>>> Makes it print extra black "space" at end of text.
    >>>>>
    >>>>> Hi Jean,
    >>>>>
    >>>>> This function is not tuned to use printer fonts. It can only reliably tell you how much space is required to display the text in
    >>>>> pixels.
    >>>>>
    >>>>>> wxfont revfonthead
    >>>>>> revfonthead =@ wxfont.new("Tahoma",14,"n","b","", error = e)
    >>>>>> wxgetscreentextextent(revfonthead, "RESIDENTIAL CONSTRUCTION", width = tw,
    >>>>>> height = th)
    >>>>>>
    >>>>>> // tw is now 299 – way too big – should be about 216 or so…
    >>>>>>
    >>>>>> integer mtw
    >>>>>> mtw = tw/app.form.currentdpi * 25400 ;// to convert to mm
    >>>>>>
    >>>>>> // then I use mtw to specify a printwidth on a printform1
    >>>>>>
    >>>>>> Any ideas on how to make it more accurate?
    >>>>>
    >>>>> The result is the value in pixels. Any conversion assumes a direct relationship with a printout, which is not the case.
    >>>>>
    >>>>> Ciao, Neil
    >>>>
    >>>> Ok so how do you estimate how much space a paragraph of text will take
    >>>> up on paper with a specified font and point size? I have many comment
    >>>> boxes that need to be printed as part of reports and they could be a
    >>>> single word, sentence or many paragraphs. I need to know if they will
    >>>> fit on the page I'm currently printing or I need to break the field and
    >>>> print what doesn't fit on the next page.
    >>>>
    >>>> I'm using printform1 for reports.
    >>>>
    >>>> Jean
    >>>>
    >>>
    >>> You are trying to recreate what the graphic report engine does, although even it won't currently break a record across pages, it
    >>> will just move it to the next page. I have an internal function that calculates the length and height of a string using the
    >>> current Windows default printer (it is a very good idea to make sure that the default printer is the one you expect to use with
    >>> SIMPOL). It is not a trivial piece of code.
    >>>
    >>> Ciao, Neil
    >>
    >> That is why I chose printform1 over the graphic report. It is
    >> conceivable that the comment field may be larger than a entire page.
    >> And I always know what the destination printer for reports is (stored in
    >> user settings table).
    >>
    >> So would you care to share your solution?
    >>
    >> Jean
    >>
    >
    > I have had a brief look, but it will take a bit of surgery to extract the code from the graphicreport library, since this is a
    > member function of a graphicreport1 object. I will see what I can do.
    >
    > Ciao, Neil

    Thank you. I'm sure I'm not the only one who will need to print comment
    fields of unrestricted length.
    Jean

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.