Skip to main content

PageOrientationHandling

Enum PageOrientationHandling 

Source
pub enum PageOrientationHandling {
    SelfCorrecting,
    RecognisesRotatedText,
    RequiresUpright,
}
Expand description

How a backend copes with a page raster whose text is not upright.

Rotated-page handling is a backend capability, not a universal guarantee. An A/B run this session against /Rotate 270 scanned pages showed the three handled cases genuinely differ: Tesseract reconstructs correct reading order on a sideways raster outright; PaddleOCR recognises the rotated text correctly (it warps each detected quad upright before running recognition) but leaves its block list in raw raster (y, x) order, so the caller must reorder; sceptre produces character garbage on the same sideways raster and only reads correctly once the page is rendered upright first. A caller that skips an upright-render step for a backend that actually needs one gets silent garbage, not an error.

§Only one variant is discriminated (#657)

Read this before “simplifying” the type. There is exactly one decision point in the codebase that inspects this value: upright_raster_for_backend (crate::extractors::pdf::ocr), which tests orientation_handling != RequiresUpright and otherwise does nothing. Every other mention forwards the value to that test. So, to that codepath, SelfCorrecting and RecognisesRotatedText are behaviourally identical — the enum is a boolean at the point of use, and the three variants describe measured backend behaviour rather than three dispatch paths.

RecognisesRotatedText’s actual remedy is not this enum. The block-order fix is the backend_options["page_rotation_degrees"] hint injected by ocr_config_with_page_rotation_hint (crate::extractors::pdf::ocr) unconditionally, for every backend, which PaddleOcrBackend::process_image reads back (page_rotation_degrees_from_backend_options -> residual_rotation_for_reorder -> reorder_blocks_for_page_rotation, crate::paddle_ocr::backend) and applies internally. Declaring RecognisesRotatedText therefore changes nothing on its own; a backend in that class must also read the hint. Conversely, gating that hint on this enum would remove a field from Tesseract’s OcrConfig and hence from the OCR cache key (hash(image + language + config)), invalidating every cached page — do not do it without its own A/B.

§PDF-route-only

Only the PDF OCR routes call OcrBackend::page_orientation_handling (the --force-ocr route via extract_with_ocr and the scanned-pages route via extract_mixed_ocr_native). The raw-image route (crate::extractors::image) never calls it: there is no /Rotate to consult, and orientation there is handled by the PP-LCNet document-orientation classifier (crate::doc_orientation) gated on OcrConfig::auto_rotate.

§Cost of the default

The trait default is RequiresUpright (deliberately the least capable option, see OcrBackend::page_orientation_handling). A backend that does not declare therefore pays, on every page with /Rotate != 0, a re-encode plus rotation of the raster in upright_raster_for_backend and a bounding-box round-trip back through undo_upright_raster_correction. That is the safe direction to be wrong in, but it is not free, and for a backend that never got measured it is not known to be necessary either.

Variants§

§

SelfCorrecting

Reconstructs reading order regardless of page rotation — safe to hand a raster in any orientation.

§

RecognisesRotatedText

Recognises rotated text correctly but emits blocks in raw raster order, so the caller must reorder.

§

RequiresUpright

Requires an upright raster; rotated text produces garbage.

Trait Implementations§

Source§

impl Clone for PageOrientationHandling

Source§

fn clone(&self) -> PageOrientationHandling

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for PageOrientationHandling

Source§

impl Debug for PageOrientationHandling

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PageOrientationHandling

Source§

fn default() -> PageOrientationHandling

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for PageOrientationHandling

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for PageOrientationHandling

Source§

impl PartialEq for PageOrientationHandling

Source§

fn eq(&self, other: &PageOrientationHandling) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for PageOrientationHandling

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for PageOrientationHandling

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more