libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

pagelayout.h (3454B)


      1 /*
      2      This file is part of libextractor.
      3      Copyright (C) 2026 Christian Grothoff
      4 
      5      libextractor is free software; you can redistribute it and/or modify
      6      it under the terms of the GNU General Public License as published
      7      by the Free Software Foundation; either version 3, or (at your
      8      option) any later version.
      9 
     10      libextractor is distributed in the hope that it will be useful, but
     11      WITHOUT ANY WARRANTY; without even the implied warranty of
     12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13      General Public License for more details.
     14 
     15      You should have received a copy of the GNU General Public License
     16      along with libextractor; see the file COPYING.  If not, write to the
     17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18      Boston, MA 02110-1301, USA.
     19  */
     20 /**
     21  * @file plugins/pagelayout.h
     22  * @brief paragraph detection from line geometry for paged formats
     23  *        (PDF, DVI) implementing the "fulltext" option
     24  * @author Christian Grothoff
     25  */
     26 #ifndef PAGELAYOUT_H
     27 #define PAGELAYOUT_H
     28 
     29 #include "extractor.h"
     30 
     31 #ifdef __cplusplus
     32 extern "C" {
     33 #endif
     34 
     35 #include "fulltext.h"
     36 
     37 /**
     38  * Geometry of one line of text on a page.  All values are in the
     39  * same (arbitrary) unit, e.g. PDF points or DVI units.
     40  */
     41 struct EXTRACTOR_PageLineGeom
     42 {
     43   /**
     44    * Horizontal position of the left end of the line.
     45    */
     46   double x0;
     47 
     48   /**
     49    * Horizontal position of the right end of the line (may be an
     50    * estimate).
     51    */
     52   double x1;
     53 
     54   /**
     55    * Vertical position of the baseline, growing downwards.
     56    */
     57   double y;
     58 
     59   /**
     60    * Font size (or line height) of the line.
     61    */
     62   double size;
     63 };
     64 
     65 
     66 /**
     67  * Decide from the line geometry which lines end a paragraph, and set
     68  * the `par_end` flags in @a pages accordingly.  Lines marked `skip`
     69  * (by #EXTRACTOR_fulltext_filter_margins_(), which should thus be
     70  * called first) are ignored.
     71  *
     72  * A line ends a paragraph if the vertical gap to the next line is
     73  * noticeably larger than the page's typical line spacing, if the next
     74  * line is indented relative to a left margin of the page, if the font
     75  * size changes noticeably, or if the line ends well before the right
     76  * margin of a justified text block.  The last line of a page ends a paragraph if it is short or
     77  * if the first line of the next page is indented.
     78  *
     79  * @param pages array of pages
     80  * @param geoms geometry of the lines, `geoms[p][i]` belongs to
     81  *        `pages[p].lines[i]`
     82  * @param num_pages number of entries in @a pages and @a geoms
     83  * @param width_tolerance relative uncertainty of the `x1` values
     84  *        (e.g. 0.02 if exact, larger if the right ends are estimated)
     85  */
     86 void
     87 EXTRACTOR_pagelayout_paragraphs_ (struct EXTRACTOR_FullTextPage *pages,
     88                                   struct EXTRACTOR_PageLineGeom *const *geoms,
     89                                   unsigned int num_pages,
     90                                   double width_tolerance);
     91 
     92 /**
     93  * Compose a Latin base letter and a combining accent into the
     94  * corresponding precomposed character, for the common accents
     95  * (U+0300-U+030C, U+0327, U+0328, and U+0337 for the Polish L with
     96  * stroke).  Dotless i and j count as i and j.
     97  *
     98  * @param base base letter
     99  * @param accent combining accent
    100  * @return precomposed character, 0 if there is none
    101  */
    102 uint32_t
    103 EXTRACTOR_pagelayout_compose_ (uint32_t base,
    104                                uint32_t accent);
    105 
    106 #ifdef __cplusplus
    107 }
    108 #endif
    109 
    110 #endif