Cannot select individual words with fixed layout .epub documents

233 views Asked by At

I have a reader app that loads .epub files and usually I have no problem with selection at all, lately I have integrated fixed layout .epub files but I'm facing a problem: when I have a box containing one line the selection works fine, but when the box contains several lines, meaning several <p></p>, I cannot select a single word from the box. On selection the whole box gets selected as shown in the screenshot. When I try the same .epub file on iBooks, the selection works fine on all text. Any idea how I can fix the issue?

Here is the code for loading the file on UiWebView.

NSString *contents = [NSString stringWithContentsOfFile:itemPath encoding:NSUTF8StringEncoding error:nil];
if (!contents) {
    contents = [NSString stringWithContentsOfFile:itemPath encoding:NSASCIIStringEncoding error:nil];
}
[readingWebView loadHTMLString:contents baseURL:baseURL];

enter image description here

enter image description here

1

There are 1 answers

0
coder On BEST ANSWER

I have finally got the answer.

When using this function:

NSString *jsString = [NSString stringWithFormat:@"document.getElementsByTagName('body')[0].webkitTextSizeAdjust= '%d%%'", font];

to set the font size some restrictions are set on the web view, one of them is related to the selection with fixed layout epubs.

I used instead:

NSString *jsString = [NSString stringWithFormat:@"document.getElementsByTagName('body')[0].style.fontSize= '%d%%'", font];