Loading ...
Sorry, an error occurred while loading the content.

Text width and height in XuiLabel

Expand Messages
  • Julien Rouiller
    Hi, ... Is there a way in XB to know the width of a char for a given font size? I would like to set a XuiLabel width to the length of the string it will
    Message 1 of 8 , Apr 5 12:16 PM
    View Source
    • 0 Attachment
      Hi,

      2 questions about text in XuiLabel:

      ---

      Is there a way in XB to know the width of a char for a given font
      size?

      I would like to set a XuiLabel width to the length of the string it
      will display + some extra margins.

      The text to display is 74 chars, Courier New, Size 12pt.

      I found XuiGetTextArraySize, but it does not help me much, because
      my text is not in an array.

      ----

      Why do the numbers display bigger than uppercase alphabetical
      characters in XuiLabels ? (I use Courier New.)

      ----

      Thanks.

      Julien
    • Steven V. Gunhouse
      On Tue, 05 Apr 2005 15:16:25 -0400, Julien Rouiller ... There is a function ... okay, two: XgrGetTextArrayImageSize (font, @text$[], @w, @h, @width, @height,
      Message 2 of 8 , Apr 5 5:32 PM
      View Source
      • 0 Attachment
        On Tue, 05 Apr 2005 15:16:25 -0400, Julien Rouiller
        <julienrouiller@...> wrote:

        > Hi,
        >
        > 2 questions about text in XuiLabel:
        >
        > ---
        >
        > Is there a way in XB to know the width of a char for a given font
        > size?
        >
        > I would like to set a XuiLabel width to the length of the string it
        > will display + some extra margins.
        >
        > The text to display is 74 chars, Courier New, Size 12pt.
        >
        > I found XuiGetTextArraySize, but it does not help me much, because
        > my text is not in an array.
        >
        > ----
        >
        > Why do the numbers display bigger than uppercase alphabetical
        > characters in XuiLabels ? (I use Courier New.)

        There is a function ... okay, two:

        XgrGetTextArrayImageSize (font, @text$[], @w, @h, @width, @height, extraX,
        extraY)
        XgrGetTextImageSize (font, @text$, @dx, @dy, @width, @height, @gap, @space)

        Basically, they render the text in an invisible grid, and take
        measurements of the resulting image.

        In XgrGetTextImageSize, dx and dy are how far the drawpoint will be moved
        (which actually means dx = width and dy = 0, if the angle of the font is
        0). In Linux, gap and space are both 0, in Windows they do have values but
        I'm not certain what they'd mean.

        XBasic doesn't make any changes to the font characteristics dependent on
        the actual text displayed, if in a certain font the numbers appear larger
        then that's just the way the font is.

        Hmm ... it looks to me like XgrGetTextArrayImageSize will give the wrong
        answer if angle != 0, I'll need to look into that ...

        --
        Steven V. Gunhouse
      • Roger Leu
        Hi There: Please do not email me any more, please. I did not know Xbasic. Roger . Steven V. Gunhouse wrote: On Tue, 05 Apr 2005
        Message 3 of 8 , Apr 5 6:44 PM
        View Source
        • 0 Attachment
          Hi There:
            Please do not email me any more, please.
          I did not know Xbasic.
           
           
          Roger .
           
           

          "Steven V. Gunhouse" <svgunhouse@...> wrote:

          On Tue, 05 Apr 2005 15:16:25 -0400, Julien Rouiller
          wrote:

          > Hi,
          >
          > 2 questions about text in XuiLabel:
          >
          > ---
          >
          > Is there a way in XB to know the width of a char for a given font
          > size?
          >
          > I would like to set a XuiLabel width to the length of the string it
          > will display + some extra margins.
          >
          > The text to display is 74 chars, Courier New, Size 12pt.
          >
          > I found XuiGetTextArraySize, but it does not help me much, because
          > my text is not in an array.
          >
          > ----
          >
          > Why do the numbers display bigger than uppercase alphabetical
          > characters in XuiLabels ? (I use Courier New.)

          There is a function ... okay, two:

          XgrGetTextArrayImageSize (font, @text$[], @w, @h, @width, @height, extraX,
          extraY)
          XgrGetTextImageSize (font, @text$, @dx, @dy, @width, @height, @gap, @space)

          Basically, they render the text in an invisible grid, and take
          measurements of the resulting image.

          In XgrGetTextImageSize, dx and dy are how far the drawpoint will be moved
          (which actually means dx = width and dy = 0, if the angle of the font is
          0). In Linux, gap and space are both 0, in Windows they do have values but
          I'm not certain what they'd mean.

          XBasic doesn't make any changes to the font characteristics dependent on
          the actual text displayed, if in a certain font the numbers appear larger
          then that's just the way the font is.

          Hmm ... it looks to me like XgrGetTextArrayImageSize will give the wrong
          answer if angle != 0, I'll need to look into that ...

          --
          Steven V. Gunhouse


          http://www.xbasic.org/

          Yahoo! Groups Links

          <*> To visit your group on the web, go to:
          http://groups.yahoo.com/group/xbasic/

          <*> To unsubscribe from this group, send an email to:
          xbasic-unsubscribe@yahoogroups.com

          <*> Your use of Yahoo! Groups is subject to:
          http://docs.yahoo.com/info/terms/





          Do you Yahoo!?
          Better first dates. More second dates. Yahoo! Personals

        • Julien Rouiller
          ... it ... because ... extraX, ... @gap, @space) ... be moved ... font is ... values but ... dependent on ... larger ... wrong ... So, the idea is just to
          Message 4 of 8 , Apr 6 9:02 AM
          View Source
          • 0 Attachment
            --- In xbasic@yahoogroups.com, "Steven V. Gunhouse"
            <svgunhouse@a...> wrote:
            > On Tue, 05 Apr 2005 15:16:25 -0400, Julien Rouiller
            > <julienrouiller@y...> wrote:
            >
            > > Hi,
            > >
            > > 2 questions about text in XuiLabel:
            > >
            > > ---
            > >
            > > Is there a way in XB to know the width of a char for a given font
            > > size?
            > >
            > > I would like to set a XuiLabel width to the length of the string
            it
            > > will display + some extra margins.
            > >
            > > The text to display is 74 chars, Courier New, Size 12pt.
            > >
            > > I found XuiGetTextArraySize, but it does not help me much,
            because
            > > my text is not in an array.
            > >
            > > ----
            > >
            > > Why do the numbers display bigger than uppercase alphabetical
            > > characters in XuiLabels ? (I use Courier New.)
            >
            > There is a function ... okay, two:
            >
            > XgrGetTextArrayImageSize (font, @text$[], @w, @h, @width, @height,
            extraX,
            > extraY)
            > XgrGetTextImageSize (font, @text$, @dx, @dy, @width, @height,
            @gap, @space)
            >
            > Basically, they render the text in an invisible grid, and take
            > measurements of the resulting image.
            >
            > In XgrGetTextImageSize, dx and dy are how far the drawpoint will
            be moved
            > (which actually means dx = width and dy = 0, if the angle of the
            font is
            > 0). In Linux, gap and space are both 0, in Windows they do have
            values but
            > I'm not certain what they'd mean.
            >
            > XBasic doesn't make any changes to the font characteristics
            dependent on
            > the actual text displayed, if in a certain font the numbers appear
            larger
            > then that's just the way the font is.
            >
            > Hmm ... it looks to me like XgrGetTextArrayImageSize will give the
            wrong
            > answer if angle != 0, I'll need to look into that ...
            >
            > --
            > Steven V. Gunhouse

            So, the idea is just to create a font using XgrCreateFont,
            and once the font has known size, to use XgrGetTextImageSize...
            Thanks! I was so obnubiled by the Xui functions that I forgot the
            Xgr ones! I'll try.

            Strange that Courier New has same height for alphabetical and
            numerical characters in all text editors I use...
            Maybe they apply some correction. I'll try with some other font.

            Julien
          • Steven V. Gunhouse
            On Wed, 06 Apr 2005 12:02:17 -0400, Julien Rouiller ... Actually, Xui will have had to create the font already, but it shouldn t matter much. You could ask
            Message 5 of 8 , Apr 6 9:15 AM
            View Source
            • 0 Attachment
              On Wed, 06 Apr 2005 12:02:17 -0400, Julien Rouiller
              <julienrouiller@...> wrote:

              >
              >
              > --- In xbasic@yahoogroups.com, "Steven V. Gunhouse"
              > <svgunhouse@a...> wrote:
              >> On Tue, 05 Apr 2005 15:16:25 -0400, Julien Rouiller
              >> <julienrouiller@y...> wrote:
              >>
              >> > Hi,
              >> >
              >> > 2 questions about text in XuiLabel:
              >> >
              >> > ---
              >> >
              >> > Is there a way in XB to know the width of a char for a given font
              >> > size?
              >> >
              >> > I would like to set a XuiLabel width to the length of the string
              > it
              >> > will display + some extra margins.
              >> >
              >> > The text to display is 74 chars, Courier New, Size 12pt.
              >> >
              >> > I found XuiGetTextArraySize, but it does not help me much,
              > because
              >> > my text is not in an array.
              >> >
              >> > ----
              >> >
              >> > Why do the numbers display bigger than uppercase alphabetical
              >> > characters in XuiLabels ? (I use Courier New.)
              >>
              >> There is a function ... okay, two:
              >>
              >> XgrGetTextArrayImageSize (font, @text$[], @w, @h, @width, @height,
              > extraX,
              >> extraY)
              >> XgrGetTextImageSize (font, @text$, @dx, @dy, @width, @height,
              > @gap, @space)
              >>
              >> Basically, they render the text in an invisible grid, and take
              >> measurements of the resulting image.
              >>
              >> In XgrGetTextImageSize, dx and dy are how far the drawpoint will
              > be moved
              >> (which actually means dx = width and dy = 0, if the angle of the
              > font is
              >> 0). In Linux, gap and space are both 0, in Windows they do have
              > values but
              >> I'm not certain what they'd mean.
              >>
              >> XBasic doesn't make any changes to the font characteristics
              > dependent on
              >> the actual text displayed, if in a certain font the numbers appear
              > larger
              >> then that's just the way the font is.
              >>
              >> Hmm ... it looks to me like XgrGetTextArrayImageSize will give the
              > wrong
              >> answer if angle != 0, I'll need to look into that ...
              >>
              >> --
              >> Steven V. Gunhouse
              >
              > So, the idea is just to create a font using XgrCreateFont,
              > and once the font has known size, to use XgrGetTextImageSize...
              > Thanks! I was so obnubiled by the Xui functions that I forgot the
              > Xgr ones! I'll try.
              >
              > Strange that Courier New has same height for alphabetical and
              > numerical characters in all text editors I use...
              > Maybe they apply some correction. I'll try with some other font.

              Actually, Xui will have had to create the font already, but it shouldn't
              matter much. You could ask your grid for its font number and use that, or
              just use XgrCreateFont.

              --
              Steven V. Gunhouse
            • Julien Rouiller
              Julien wrote: (...) ... font size? (...) ... (...) Steven answered: (...) ... angle of the font is 0). In Linux, gap and space are both 0, in Windows they do
              Message 6 of 8 , Apr 6 3:36 PM
              View Source
              • 0 Attachment
                Julien wrote:
                (...)
                > >> > Is there a way in XB to know the width of a char for a given
                font size?
                (...)
                > >> > Why do the numbers display bigger than uppercase alphabetical
                > >> > characters in XuiLabels ? (I use Courier New.)
                (...)

                Steven answered:
                (...)
                > >> XgrGetTextImageSize (font, @text$, @dx, @dy, @width, @height,
                > > @gap, @space)
                > >>
                > >> Basically, they render the text in an invisible grid, and take
                > >> measurements of the resulting image.
                > >>
                > >> In XgrGetTextImageSize, dx and dy are how far the drawpoint will
                > > be moved (which actually means dx = width and dy = 0, if the
                angle of the font is 0). In Linux, gap and space are both 0, in
                Windows they do have values but I'm not certain what they'd mean.
                (...)
                > >> XBasic doesn't make any changes to the font characteristics
                > > dependent on the actual text displayed, if in a certain font the
                numbers appear larger then that's just the way the font is.
                (...)

                Julien answered:
                > > So, the idea is just to create a font using XgrCreateFont,
                > > and once the font has known size, to use XgrGetTextImageSize...
                (...)
                > > Strange that Courier New has same height for alphabetical and
                > > numerical characters in all text editors I use...
                (...)

                Steven answered:
                > Actually, Xui will have had to create the font already, but it
                shouldn't matter much. You could ask your grid for its font number
                and use that, or just use XgrCreateFont.

                Julien writes:

                I just observed that if you choose a font size of 240 or 260,
                alphabetical and numerical characters display with the same height.
                But if font size is 280, then numerical characters display bigger...
                Strange! Maybe some rounding error...


                The html help tells for XgrCreateFont and other functions that :
                "fontSize is ten times the point size".

                It looks like it is rather more or less 20 times.

                However, using a font size of 260 for a 13 point size gives text
                smaller that 13pt. Any idea ?

                Thanks.
                Julien
              • Steven V. Gunhouse
                On Wed, 06 Apr 2005 18:36:07 -0400, Julien Rouiller ... If so, then it a rounding error inside Windows itself. We just tell Windows what size we want, it
                Message 7 of 8 , Apr 6 5:37 PM
                View Source
                • 0 Attachment
                  On Wed, 06 Apr 2005 18:36:07 -0400, Julien Rouiller
                  <julienrouiller@...> wrote:

                  > I just observed that if you choose a font size of 240 or 260,
                  > alphabetical and numerical characters display with the same height.
                  > But if font size is 280, then numerical characters display bigger...
                  > Strange! Maybe some rounding error...

                  If so, then it a rounding error inside Windows itself. We just tell
                  Windows what size we want, it handles everything from there.

                  > The html help tells for XgrCreateFont and other functions that :
                  > "fontSize is ten times the point size".
                  >
                  > It looks like it is rather more or less 20 times.
                  >
                  > However, using a font size of 260 for a 13 point size gives text
                  > smaller that 13pt. Any idea ?

                  It is 20 times, but we request that Windows not count "internal leading"
                  in the font size. (At one time I may have known what that referred to, but
                  at the moment I'm not completely sure. Some sort of padding in the
                  characters themselves.) So I can't say that our size of 240 is exactly the
                  same as a 12 point as reported by some other program. Might actually be,
                  just have slightly different line spacing.

                  When I was working on the code some time ago, there was one section that
                  used a factor of 10 and then all the rest used 20, so of course I changed
                  that one section to agree with all the others.

                  --
                  Steven V. Gunhouse
                • Julien Rouiller
                  ... height. ... bigger... Strange! Maybe some rounding error... ... tell Windows what size we want, it handles everything from there. ... leading in the font
                  Message 8 of 8 , Apr 6 11:28 PM
                  View Source
                  • 0 Attachment
                    --- In xbasic@yahoogroups.com, "Steven V. Gunhouse"
                    <svgunhouse@a...> wrote:
                    > On Wed, 06 Apr 2005 18:36:07 -0400, Julien Rouiller
                    > <julienrouiller@y...> wrote:
                    >
                    > > I just observed that if you choose a font size of 240 or 260,
                    > > alphabetical and numerical characters display with the same
                    height.
                    > > But if font size is 280, then numerical characters display
                    bigger... Strange! Maybe some rounding error...
                    >
                    > If so, then it a rounding error inside Windows itself. We just
                    tell Windows what size we want, it handles everything from there.

                    > > The html help tells for XgrCreateFont and other functions that:
                    > > "fontSize is ten times the point size".
                    > < It looks like it is rather more or less 20 times.
                    > > However, using a font size of 260 for a 13 point size gives text
                    > > smaller that 13pt. Any idea ?
                    >
                    > It is 20 times, but we request that Windows not count "internal
                    leading" in the font size. (At one time I may have known what that
                    referred to, but at the moment I'm not completely sure. Some sort of
                    padding in the characters themselves.) So I can't say that our size
                    of 240 is exactly the same as a 12 point as reported by some other
                    program. Might actually be, just have slightly different line
                    spacing.
                    >
                    > When I was working on the code some time ago, there was one
                    section that used a factor of 10 and then all the rest used 20, so
                    of course I changed that one section to agree with all the others.

                    > Steven V. Gunhouse

                    Thanks. In fact a 260 font size looks more or less like 10 pt.

                    Julien
                  Your message has been successfully submitted and would be delivered to recipients shortly.