pdfium_range.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) 2010 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef PDF_PDFIUM_PDFIUM_RANGE_H_
  5. #define PDF_PDFIUM_PDFIUM_RANGE_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/memory/raw_ptr.h"
  9. #include "pdf/page_orientation.h"
  10. #include "pdf/pdfium/pdfium_page.h"
  11. #include "ui/gfx/geometry/point.h"
  12. #include "ui/gfx/geometry/rect.h"
  13. namespace chrome_pdf {
  14. constexpr char16_t kZeroWidthSpace = 0x200B;
  15. constexpr char16_t kPDFSoftHyphenMarker = 0xFFFE;
  16. // Helper for identifying characters that PDFium outputs, via FPDFText_GetText,
  17. // that have special meaning, but should not be included in things like copied
  18. // text or when running find.
  19. bool IsIgnorableCharacter(char16_t c);
  20. // Describes location of a string of characters.
  21. class PDFiumRange {
  22. public:
  23. PDFiumRange(PDFiumPage* page, int char_index, int char_count);
  24. PDFiumRange(const PDFiumRange& that);
  25. ~PDFiumRange();
  26. // Update how many characters are in the selection. Could be negative if
  27. // backwards.
  28. void SetCharCount(int char_count);
  29. int page_index() const { return page_->index(); }
  30. int char_index() const { return char_index_; }
  31. int char_count() const { return char_count_; }
  32. // Gets bounding rectangles of range in screen coordinates.
  33. const std::vector<gfx::Rect>& GetScreenRects(
  34. const gfx::Point& point,
  35. double zoom,
  36. PageOrientation orientation) const;
  37. // Gets the string of characters in this range.
  38. std::u16string GetText() const;
  39. private:
  40. // The page containing the range. Must outlive `this`.
  41. raw_ptr<PDFiumPage> page_;
  42. // Index of first character.
  43. int char_index_;
  44. // How many characters are part of this range (negative if backwards).
  45. int char_count_;
  46. // Cache of ScreenRect, and the associated variables used when caching it.
  47. mutable std::vector<gfx::Rect> cached_screen_rects_;
  48. mutable gfx::Point cached_screen_rects_point_;
  49. mutable double cached_screen_rects_zoom_ = 0;
  50. };
  51. } // namespace chrome_pdf
  52. #endif // PDF_PDFIUM_PDFIUM_RANGE_H_