Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Mar 09, 2020 Mar 09, 2020

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.

TOPICS
Acrobat SDK and JavaScript
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 10, 2020 Mar 10, 2020

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 diff

...
Translate
Community Expert ,
Mar 09, 2020 Mar 09, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 09, 2020 Mar 09, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 10, 2020 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 10, 2020 Mar 10, 2020

Then that method won't work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 10, 2020 Mar 10, 2020

Maybe you can work with the PDStyle of individual characters. Quads aren’t made to tell you font size, they are made to tell you about space occupied; quads help with many fuzzy logic decisions. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 10, 2020 Mar 10, 2020

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 10, 2020 Mar 10, 2020

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 10, 2020 Mar 10, 2020
LATEST

Thank you very much for your answer. I will do so.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 09, 2020 Mar 09, 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... 

 

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 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 09, 2020 Mar 09, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines