Skip to main content
Boris56
Known Participant
March 9, 2020
Answered

How to determine if a character is a superscript or subscript?

  • March 9, 2020
  • 3 replies
  • 3051 views

Hi,

I need to determine if a character is a superscript or subscript. Using the PDWordFinder object, I find all the text on the current page of the document. Each character of this text refers to a specific PDWord object. I tried using the PDWordGetCharacterTypes method to get the attributes of each character, but I did not find the properties of a superscript or subscript among the character attributes. Then I decided that I could find these properties in the PDFont object of the current character. But there I also could not find the necessary properties.

I would be grateful for any help.

This topic has been closed for replies.
Correct answer Test Screen Name

The font size I really can find out:
ASFixed fontSize = PDStyleGetFontSize (pdStyle);
But I would like to know the size of the area occupied by the symbol.


You'd need to get the individual character metrics and apply the font size. However, this is going to go up and down as you read ordinary characters along a line. Look at "along". The "l" and "g" have more vertical height and a different baseline. This is only useful for graphics work. Use the font size to start the guess as to whether you have subscripts or superscripts. At least, that's how I'd do it... because this is an exercise in guesswork each programmer may do it differently and get different results.

3 replies

ls_rbls
Community Expert
Community Expert
March 9, 2020

Hi,

 

I found the following links to be useful in as a starting point for building your javascript (if at all possible):

 

https://stackoverflow.com/questions/46444635/how-to-check-a-string-contains-superscript-or-subscript-in-java/46447375#46447375 

 

See here for complete unicode table of subscript alphabet: https://stackoverflow.com/questions/17908593/how-to-find-the-unicode-of-the-subscript-alphabet 

 

An example of a script to accomplish this in C+ to check a string: https://www.codeproject.com/Questions/990692/How-to-check-a-string-contains-superscript-or-subs 

 

Using iText library example:http://itextsharp.10939.n7.nabble.com/Super-and-Subscript-td763.html 

 

Applying superscript example in Photoshop: https://community.adobe.com/t5/photoshop/applying-superscript-to-textitem/td-p/10482051?page=1 

Legend
March 9, 2020

Ooh, yes, thank you for that. So, you need to handle BOTH superscript Unicode AND regular characters set on a higher baseline, perhaps smaller. Similarly there are subscript characters AND characters set smaller, perhaps on the same baseline, perhaps a little below, but definitely overlapping. The Word Finder may not return these in the natural order, you should do your own X,Y sorting.

Legend
March 9, 2020

There is absolutely nothing in PDF for superscript or subscript. Or justification, paragraph, hyphenation, column or any of these concepts. Only characters on the page. So you have to do your own guesswork. You can indeed analyze a line to find the dominant baseline and look for exceptions to it. The font size might also be a clue. Two programmers will get different results.

Boris56
Boris56Author
Known Participant
March 10, 2020

And how to determine the area occupied by a symbol? The PDWordGetCharQuad method shows the same vertical areas  for all characters of one word.

try67
Community Expert
Community Expert
March 10, 2020

Then that method won't work.

try67
Community Expert
Community Expert
March 9, 2020

I'm not too familiar with the plugins SDK, but if there isn't a specific property that defines the text as being super- or subscript (which is what I suspect) maybe you can find out the quads or font size of the word and compare it to the ones before (and/or after) it to find it out yourself.