Skip to main content

How to get the number of chars represented by a GlyphVector?

2 replies [Last post]
Anonymous

Hello again,

I am trying to get the number of chars that a GlyphVector represents The
following line seems to work:

myGlyphVector.getGlyphCharIndex(myGlyphVector.getNumGlyphs());

The problem is that reading the documentation for getGlyphCharIndex(int
glyphIndex) gives me the feeling that the method should throw an
IndexOutOfBounds exception if the value of glyphIndex equals the number
of glyphs (just like you get an exception when calling
myArray[myArray.length]). But on the other hand it does not explicitly
say that any parameter greater or equal to the number of glyphs will
throw an exception. Can I reliably use the method to determine the
number of chars in a glyph vector or is there a chance that my code will
not work on other VMs or future versions? Maybe the documentation should
be updated to clarify the behaviour? Or is there even a better day to
get the number of chars represented by a glyphVector?

Thanks

Jan

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Phil Race

I do not think its 100% safe. Since there is not necessarily a 1:1 mapping
of glyphs to chars, then some chars may be completely elided away and
have no representation in the returned set from calling this API on each
of the glyph indices. I'd have to check if its universally true but in our
implementation elided away chars typically are replaced by the
special 'invisible glyph', so it may appear to work for that reason,
but that's not guaranteed by spec.

-phil.

Jan Bösenberg (INCORS GmbH) wrote:
> Hello again,
>
> I am trying to get the number of chars that a GlyphVector represents The
> following line seems to work:
>
> myGlyphVector.getGlyphCharIndex(myGlyphVector.getNumGlyphs());
>
> The problem is that reading the documentation for getGlyphCharIndex(int
> glyphIndex) gives me the feeling that the method should throw an
> IndexOutOfBounds exception if the value of glyphIndex equals the number
> of glyphs (just like you get an exception when calling
> myArray[myArray.length]). But on the other hand it does not explicitly
> say that any parameter greater or equal to the number of glyphs will
> throw an exception. Can I reliably use the method to determine the
> number of chars in a glyph vector or is there a chance that my code will
> not work on other VMs or future versions? Maybe the documentation should
> be updated to clarify the behaviour? Or is there even a better day to
> get the number of chars represented by a glyphVector?
>
>
> Thanks
>
> Jan
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff JAVA2D-INTEREST". For general help, send
> email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

"Jan Bösenberg (INCORS GmbH)"

You are right, I did not think that chars may not be represented by a
glyph at all. But this is no problem, I was just hoping there would be a
way to avoid storing the number of chars represented by a glyph vector
separately, which is what I am doing currently.

Thanks again,

Jan

Phil Race schrieb:
> I do not think its 100% safe. Since there is not necessarily a 1:1
> mapping
> of glyphs to chars, then some chars may be completely elided away and
> have no representation in the returned set from calling this API on each
> of the glyph indices. I'd have to check if its universally true but in
> our
> implementation elided away chars typically are replaced by the
> special 'invisible glyph', so it may appear to work for that reason,
> but that's not guaranteed by spec.
>
> -phil.
>
>
>
> Jan Bösenberg (INCORS GmbH) wrote:
>> Hello again,
>>
>> I am trying to get the number of chars that a GlyphVector represents The
>> following line seems to work:
>>
>> myGlyphVector.getGlyphCharIndex(myGlyphVector.getNumGlyphs());
>>
>> The problem is that reading the documentation for getGlyphCharIndex(int
>> glyphIndex) gives me the feeling that the method should throw an
>> IndexOutOfBounds exception if the value of glyphIndex equals the number
>> of glyphs (just like you get an exception when calling
>> myArray[myArray.length]). But on the other hand it does not explicitly
>> say that any parameter greater or equal to the number of glyphs will
>> throw an exception. Can I reliably use the method to determine the
>> number of chars in a glyph vector or is there a chance that my code will
>> not work on other VMs or future versions? Maybe the documentation should
>> be updated to clarify the behaviour? Or is there even a better day to
>> get the number of chars represented by a glyphVector?
>>
>>
>> Thanks
>>
>> Jan
>>
>> ===========================================================================
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in
>> the body
>> of the message "signoff JAVA2D-INTEREST". For general help, send
>> email to
>> listserv@java.sun.com and include in the body of the message "help".
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".