title: Swift problem when adding annotations with regex to pdf page
body: <p>I want to search for a regex in a pdf, and add annotations to it according, using the results from the regex. I have built a simple function that does this. As the amazing community  (really amazing people who used their time helping me) posted I can I can use the <em>decomposedStringWithCompatibilityMapping</em> to search for the desired expression correctly in the pdf, but afterwards when I perform a pdf selection to find the bounds of it, I encounter a difference. I send you my code and some pictures.</p>
  <pre><code>func performRegex(regex:String, on pdfPage:PDFPage)  {
      guard let pdfString = pdfPage.string?.precomposedStringWithCanonicalMapping else { return }
      guard let safeRegex = try? NSRegularExpression(pattern: regex, options: .caseInsensitive) else { return }
      let results = safeRegex.matches(in: pdfString, options: .withoutAnchoringBounds, range: NSRange(pdfString.startIndex..., in: pdfString))
      pdfPage.annotations.forEach { pdfPage.removeAnnotation($0)}
      results.forEach { result in
          let bbox = pdfPage.selection(for: result.range)?.bounds(for: pdfPage)
          let annotation = PDFAnnotation(bounds: bbox!, forType: .highlight, withProperties: nil)
          annotation.color = .yellow
          annotation.contents = String(pdfString[Range(result.range, in:pdfString)!])
          pdfPage.addAnnotation(annotation)
      }
  }
  </code></pre>
  <p>The problem is that when I do this and enter this expression [0-9] all my results are shifted:
  <a href="https://i.stack.imgur.com/cFpYC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cFpYC.png" alt="shifted results" /></a></p>
  <p>While if I don't use precomposedStringWithCanonicalMapping, all my results are not shifted but I will encounter an error when I get a special character.
  <a href="https://i.stack.imgur.com/zblFE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zblFE.png" alt="not shifted results" /></a></p>
  <p>The problem (I suspect) is in this line of code.</p>
  <pre><code>let bbox = pdfPage.selection(for: result.range)?.bounds(for: pdfPage)
  </code></pre>
  <p>But I don't know any work arround for it.</p>
  <p>Please if anyone can give me some help!</p>
  <p>Thanks a lot</p>