Universal DOC, DOCX and INDD document typesetting engine and method

By combining the streaming document model and the layout memory document model, efficient conversion of streaming document formats such as DOC, DOCX and INDD to layout documents is achieved, solving the problem of inconsistent formats, providing high-fidelity layout document output and table calculation functions, and improving the compatibility and efficiency of document typesetting.

CN113011129BActive Publication Date: 2025-09-19冯春霖
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110418589.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-19
Publication Date
2025-09-19
Estimated Expiration
2041-04-19

AI Technical Summary

Technical Problem

Existing technologies cannot effectively convert streaming document formats such as DOC, DOCX, and INDD into a unified layout document format, and lack compatibility and efficient typesetting software, resulting in inconsistent format conversion and inconvenience in use.

Method used

A universal DOC, DOCX, and INDD document typesetting engine and method are provided, including a streaming document model and a layout memory document model. The engine and method realize the conversion of streaming documents to layout documents through document parsing, linearization processing, layout control, page typesetting, content box typesetting, and other steps.

Benefits of technology

It achieves high-fidelity conversion from streaming documents to layout documents, supports multiple document formats, and can output layout file formats such as PDF and PostScript. It is suitable for office documents and book and magazine layout, and has table calculation functions, which improves the compatibility and efficiency of document typesetting.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113011129B_ABST
    Figure CN113011129B_ABST
Patent Text Reader

Abstract

The present invention provides a universal DOC, DOCX and INDD document typesetting engine and method, which performs typesetting calculations on mainstream office documents DOC and DOCX and book publishing and magazine typesetting documents INDD, and parses the DOC, DOCX or INDD into a unified streaming document memory model through a streaming document parser; pre-processes the streaming document memory model, loads referenced documents, calculates and inserts numerical numbers of paragraphs; performs CSS format determination, word recognition, and character and word width and height calculations on the pre-processed streaming document memory model; performs page-by-page, paragraph-by-paragraph, and word-by-word calculations on the input streaming document memory model, and stores the calculation results in a layout memory document; performs subsequent processing on the typesetting calculation results to determine page number references, total number of pages, and table column calculations in the document; and converts the layout memory document into an external storage file format to achieve persistent storage of the typesetting results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a document typesetting method, in particular to a universal DOC, DOCX and INDD document typesetting engine and method. Background Art

[0002] DOC and DOCX are flow-based documents, currently the most widely used flow-based document formats and the primary primary file format for daily work. INDD documents are the mainstream document format used internationally for newspaper and magazine layout. DOC and DOCX are purely flow-based documents, with content driving the creation of new pages when printed. INDD documents, on the other hand, combine pages with flow-based content. When creating and editing a document, you first create a page, then add content boxes, and then enter flow-based content within those boxes. This feature of INDD makes it ideal for the complex and flexible layouts of books and magazines, allowing for independent content to be displayed anywhere on the page. INDD's content boxes are similar to the body of DOC and DOCX pages and can be divided into columns. In terms of flow-based content, INDD is largely similar to DOC and DOCX, primarily consisting of paragraphs or tables, and content styles follow the CSS style stacking and inheritance logic.

[0003] PDF is a file storage and display format that is independent of operating systems, applications, and hardware. It is currently the most commonly used document format in the publishing industry, accurately reproducing every character, color, and image of the original document.

[0004] Although the relevant standards for DOC, DOCX, PDF, and PostScript files have been opened, since the content of streaming documents does not have coordinate information, the formats presented after opening the files by various display software are inconsistent, making it difficult to convert them into layout documents with a fixed and unified format.

[0005] In the process of converting streaming documents into layout documents, typesetting software is the most important and complex software product. However, its core technology is controlled by a few large companies, resulting in high costs and inconvenience. Furthermore, there is currently no commercially available method that can simultaneously typeset and convert DOC, DOCX, and INDD documents into layout documents. This invention fills a gap in this field of technology in China. Summary of the Invention

[0006] The present invention provides a universal DOC, DOCX and INDD document typesetting engine and method, which solves the typesetting problem of formatted documents using streaming documents. The technical solution is as follows:

[0007] A universal DOC, DOCX and INDD document typesetting engine comprises a streaming document model and a layout memory document model, which are respectively used to generate a streaming document memory model from a document to be processed and to form a layout memory document from the streaming document memory model; the streaming document model comprises a document parser, a document preprocessor, a document linearization processor and a font parser, and the operations performed on the document to be processed in sequence are: reading the document, loading referenced external documents, processing paragraph styles and character formats, and loading fonts used in the document; the layout memory document model comprises a layout controller, a page typeseter, a content box typeseter, a content column typeseter and a typesetting post-processor, and processes the streaming document memory model in sequence to form a final layout memory document.

[0008] The document parser is used to read various parts of the content of the document to be processed, including parsing the layout definition and style definition in the document to be processed, as well as parsing the content and format of the document to be processed, and then generating the corresponding layout, style and content elements in the streaming document model StyledDocument. According to the attribute indication of the document to be processed, the corresponding DOC parser, DOCX parser or INDD parser is selected.

[0009] The document linearization processor includes the following contents: (1) analyzing each character of all paragraphs in the document to be processed and establishing a character model of the paragraph; (2) processing paragraph and character styles, and calculating the specific style of each character based on CSS style rules and content style settings, wherein the specific style includes font, font size, color, background color, and whether there is underline or strikethrough; (3) analyzing the paragraph character model to perform word recognition and calculate the width and height of each word.

[0010] The layout controller is used to start the core typesetting function of the streaming document memory model, which includes a Word document layout controller and an InDesign document layout controller; the Word document layout controller selects the corresponding page layout according to the current page number, and then starts the page layout device to typeset the current page; the InDesign document layout controller scans each page of the document and its basic pages, and then starts the page layout device to typeset the current page and its basic pages of the InDesign document.

[0011] The page layouter includes a Word page layouter and an InDesign page layouter; the Word page layouter is used to check whether the current page has a header and footer. If so, the content of the header and footer is layouted first, the height of the header and footer is calculated, and then the size of the displayable area of ​​the text is calculated; the Word page layouter dynamically calculates the coordinates, width and height of the content box for the header and footer and the text, and creates a content box in the layout document page, and then starts the content box layouter; the InDesign page layouter scans all content boxes in a page, and creates a content box in the layout document page according to the coordinates and width and height specified by each content box, and then starts the content box layouter.

[0012] The content box layout device is used to check the number of columns of the current content box and the width of each column, create a content column in the corresponding layout document content box, and associate the content column with the content display container, and then start the content column layout device to put the current content into the content column; the content column layout device is used to scan the content of the section in the streaming document memory model. If the current content is a paragraph, the paragraph layout device is started; if it is a table, the table layout device is started.

[0013] The table typeset is provided with a footer row function, which supports calculation functions for table columns, including maximum value, minimum value, average value and sum; when a table is divided into different pages, the footer row will be displayed on each page, and the table content of the footer row is the result of the numerical calculation of the column in which it is located, and the header table does not participate in the calculation. Each table in the column can only have one paragraph. If there is more than one paragraph, only the first paragraph is processed.

[0014] A general DOC, DOCX and INDD document typesetting method comprises the following steps:

[0015] S1: Generate a streaming document memory model through the document parser.

[0016] S2: Preprocessing the streaming document memory model: Finding and loading external documents referenced in the document to be processed, finding and collecting the directory definition and content items of the document to be processed, and calculating and inserting the numerical numbers of the paragraphs of the document to be processed. The external documents are parsed by the document parser and inserted into the corresponding position of the main document.

[0017] S3: The preprocessed streaming document memory model is linearized through the document linearizer to process paragraph styles and character formats;

[0018] S4: Font loading and parsing through the font parser;

[0019] S5: Selecting a corresponding layout controller according to the document type of the input document, wherein the Word document layout controller selects a corresponding page layout according to the current page number, and then starts the page layout controller to typeset the current page; the InDesign document layout controller scans each page of the document and its base page, and then starts the page layout controller to typeset the current page and its base page;

[0020] S6: Calling the page layout: The Word page layout dynamically calculates the coordinates, width and height of the content boxes for the header, footer and body text and creates the content boxes in the layout document page; the InDesign page layout scans all content boxes in a page and creates content boxes in the layout document page according to the coordinates, width and height specified for each content box;

[0021] S7: Call the content frame typeset: used to check the number of columns of the current content frame and the width of each column;

[0022] S8: Call the content column layout device; scan the section content. If the current content is a paragraph, start the paragraph layout device and continue to step S9. If it is a table, start the table layout device and jump to step S11.

[0023] S9: Calling the paragraph layout device: Calculating the paragraph display area based on the paragraph style, and starting the line layout device to calculate the line break processing of the paragraph content;

[0024] S10: calling the line typeset: applying for a line of space from the content column with the height of the first word of the current content, scanning and calculating each character until the line space is full or the paragraph content ends, if the line space is full and there is still content in the paragraph, then line break processing is performed, when a line of typesetting is completed, the precise position and space occupied by the line in the content column of the layout file are determined according to the line content height and the paragraph line height style, if there is insufficient space in the content column, then the paragraph is paged; each time the line typeset is called, a line of content in the layout memory document is generated and placed in the content column of the layout memory document, and the paragraph typeset is called cyclically until the content of the paragraph ends;

[0025] S11: Calling the table layout device: Based on the style and content of the table in the flow document, a corresponding layout document table row and column structure is created and placed in the layout document. Each table can be regarded as a content column. The table layout device will call the content column layout device to layout each table. Repeat the layout calculation for all the contents of the document until the layout calculation of the entire document is completed.

[0026] S12: Calling the typesetting post-processor: calculating the total number of document pages, replacing page number references, content alignment, and table column calculation, and adjusting the coordinates of some content;

[0027] S13: Calling a layout document converter: using a document format that can be converted between internal and external storage media to persist the layout results.

[0028] Furthermore, in step S10, when performing line break processing, factors affecting line break include spaces, hyphens, punctuation marks, and non-breaking spaces; the following three rules are involved:

[0029] (1) For Western languages, spaces are the basis for word recognition. If a paragraph is set not to allow line breaks at hyphens, it is necessary to break at spaces;

[0030] (2) Otherwise, check whether the current word has an explicit hyphen. If not, search the dictionary table for the implicit hyphen of the current word. If there is an explicit or implicit hyphen, wrap the line at the hyphen closest to the end of the line.

[0031] (3) No matter how many spaces there are at the end of a line, they will be ignored. Punctuation marks cannot appear at the beginning of a line; lines cannot be broken at non-breaking spaces.

[0032] According to this rule, the line typesetter checks whether a line break can be made at the current character. If not, it searches for a line break point from the end of the line toward the beginning of the line. If no line break point is found even at the beginning of the line, it ignores all rules and directly breaks the line at the current character.

[0033] Furthermore, in step S11, the table layout device creates a corresponding layout document row and column structure according to the style and content of the table in the flow document, and places it into the layout document, including the following steps:

[0034] (1) Determine the number of columns in the table, create a two-dimensional array, and determine the specific row and column position of each table in the table based on the cross-row and cross-column properties of each table;

[0035] (2) Calculate the width of each table and calculate its content column based on the table line width and inner margin;

[0036] (3) Start the content column typeset to typeset and calculate the table content. The height of each table is determined by the table content typeset calculation result and the row height attribute of the row, and then the height of the row is determined. Then, the height of all tables in the row is reversed to unify the height. After all tables are typeset, the height of the entire table is determined.

[0037] (4) If the current content column can accommodate the table, put it directly into the content column, otherwise the table is paginated;

[0038] Because of the control of orphan lines in paragraphs, when a page is full, it is not known how many lines of this paragraph will be on the next page. Therefore, the paging process is designed to be triggered when the layout of the first paragraph of the next page is completed. That is, when the layout of the first paragraph of the next page is completed, paging control is performed on the previous page to detect whether there is content that needs to be moved to the next page; if the first line of the next page is an orphan line and the paragraph it belongs to has content on the previous page, then move one line from the previous page to the next page, and then find the paging point of the previous page.

[0039] The universal DOC, DOCX and INDD document typesetting engine and method can perform typesetting calculations on mainstream office documents DOC, DOCX and Adobe book publishing and magazine layout documents INDD. The typesetting calculation results can be persistently saved as files that are independent of specific output formats or display devices, and can also be directly output to mainstream layout file formats such as PDF, PostScript, PCL, etc. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 It is a schematic diagram of the application logic of the universal DOC, DOCX and INDD document typesetting engines;

[0041] Figure 2 is a schematic diagram of the architecture of the streaming document model;

[0042] Figure 3 is a schematic diagram of the architecture of the layout memory document model;

[0043] Figure 4 It is a flowchart of the general DOC, DOCX and INDD document typesetting method. DETAILED DESCRIPTION

[0044] The universal DOC, DOCX, and INDD document layout engine and method provided by the present invention are compatible with the streaming document description models of DOC, DOCX, and INDD. Based on this document model, a series of layout calculations are performed on the content of the document to be processed, successfully outputting high-fidelity layout document results. The document layout engine and specific processing methods of the present invention are as follows:

[0045] like Figure 1As shown, a universal DOC, DOCX, and INDD document layout engine Composer includes a streaming document model and a layout memory document model, which are respectively used to generate a streaming document memory model from a document to be processed and to form a layout memory document from the streaming document memory model. The streaming document model includes a document parser, a document preprocessor, a document linearizer, and a font parser. The operations performed on the document to be processed are: reading the document, loading referenced external documents, processing paragraph styles and character formats, and loading fonts used in the document. The layout memory document model includes a layout controller, a page layout controller, a content box layout controller, a content column layout controller, and a layout post-processor. The streaming document memory model is processed in sequence to form a final layout memory document from the overall to the detailed.

[0046] 1. Streaming Document Model StyledDocument

[0047] like Figure 2 As shown, in order to be compatible with DOC, DOCX and INDD document formats at the same time, the tree-structured streaming document model StyledDocument can use two branches to describe the document, one branch is the document layout branch, and the other branch is the document content branch. Among the properties of the document to be processed, there is an item indicating whether the document is DOC, DOCX or INDD. The document layout branch first processes multiple pages, and each page processes multiple content boxes, and each content box is formed into a content column. The document content branch is based on sections, and each section involves paragraphs or tables. For paragraphs, it involves text, pictures and fields. The content of a table can be paragraphs and tables. The table is formed by table rows, and the table rows contain tables.

[0048] 1. Document Parser

[0049] The document parser is used to read the various parts of the document to be processed, including parsing the layout and style definitions in the document to be processed, as well as parsing the content and format of the document to be processed, and then generating the corresponding layout, style, and content elements in the streaming document model StyledDocument. The document parsers involved include DOC parsers, DOCX parsers, and INDD parsers. Based on the attribute indication of the document to be processed, it determines whether the document is DOC, DOCX, or INDD, and selects the corresponding parser.

[0050] 2. Document Preprocessor

[0051] The document preprocessor is used to search the full text of the document to be processed and find and load external documents referenced in the document to be processed. For external documents, it is necessary to find and collect the directory definition and content items of the external document; at the reference point of the external document, the numerical number of the paragraph referencing the external document is calculated and inserted.

[0052] 3. Document linearization processor TextStoryBuilder

[0053] The document linearization processor is used to process the following: (1) analyze each character of all paragraphs in the document to be processed and establish a character model of the paragraph; (2) process the paragraph and character styles, and calculate the specific style of each character (such as font, font size, color, background color, whether there is underline or strikethrough, etc.) according to CSS style rules and content style settings; (3) analyze the paragraph character model to perform word recognition and calculate the width and height of each word.

[0054] 4. Font Reader

[0055] The font parser is responsible for loading and parsing the fonts used in the document being processed. The width and height of each character in the document are defined by its font file. To calculate the coordinates of the document's content, the width and height of each character must be accurately calculated. The font parser loads the font file and analyzes the character's outline, baseline, and other attributes, laying the foundation for typesetting calculations for the entire document.

[0056] Through several components of the above streaming document model, it is possible to generate a streaming document memory model from the document to be processed.

[0057] 2. Layout Memory Document Model

[0058] like Figure 3 As shown, the layout memory document model sequentially processes pages, content boxes, content columns, rows and tables, text, and images. Tables are composed of rows, and the table content in each row may involve content columns. This process transforms the streaming document memory model from the overall to the detailed, forming a layout memory document.

[0059] 1. Layout Controller

[0060] The layout controller is used to start the core typesetting function of the streaming document memory model. According to the page-based organization of INDD documents, or combined with the page settings of each section of DOC and DOCX documents, each section can be regarded as a series of pages that can be automatically selected and created, and referenced external documents can also be inserted into the main document in the form of pages.

[0061] The layout controller is divided into two types: Word document layout controller and InDesign document layout controller. The corresponding layout controller is selected based on the document type of the input document to be processed. Document layout mainly refers to information such as page size, orientation, page margins, headers / footers, different home pages, different odd and even pages, and content display column.

[0062] Word documents are driven entirely by streaming content and organized into sections. Each section has a specific layout. The Word document layout controller selects the appropriate page layout based on the current page number and then launches the page layout controller to layout the current page. For Word documents, if the body content box is full and there is still content to be included, the Word page layout controller will create a new page in the layout document to continue layouting the remaining content.

[0063] InDesign documents are primarily driven by pages and the content boxes within them. Content boxes contain fluid content, and content boxes on the same or different pages can be connected, allowing content to flow within these connected boxes. Each InDesign page can be associated with a number of base pages, and the final displayed or output page content is a superposition of the content of each InDesign page and its base pages. The InDesign document layout controller scans each document page and its base pages, then launches the page compositor to lay out the current page and its base pages.

[0064] 2. Page Composer

[0065] The page layout includes a Word page layout and an InDesign page layout. The Word page layout checks whether the current page has a header and footer. If so, it first layouts the header and footer content, calculates the height of the header and footer, and then calculates the size of the displayable area for the text. The Word page layout dynamically calculates the coordinates, width, and height of the content box for the header, footer, and text, creates the content box in the layout document page, and then starts the content box layout.

[0066] The InDesign page compositor scans all content boxes on a page and creates content boxes in the layout document page according to the coordinates and width and height specified for each content box, and then starts the content box compositor.

[0067] 3. Content box layout tool FrameComposer

[0068] The content box layout inspects the number of columns in the current content box and the width of each column. It then creates content columns within the corresponding layout document content box and associates them with the content display container. It then launches the content column layout inspector to typeset the current content into the content column. The content box layout inspectors for Word and InDesign documents use the same logic, unifying the layout engine processing logic.

[0069] 4. Column Composer

[0070] The content column typeset is used to scan the content of a section in the streaming document memory model. If the current content is a paragraph, the paragraph typeset is started; if it is a table, the table typeset is started.

[0071] 4.1 Paragraph Composer

[0072] The paragraph typeset is used to calculate the paragraph display area based on the paragraph style, such as indentation and leading and trailing spacing, and start the line typeset to calculate line breaks for the paragraph content.

[0073] 4.11 Line Composer

[0074] The line typesetter is used to apply for a line of space from the content column at the height of the first word of the current content, scan and calculate each character until the line space is full or the paragraph content ends. If the line space is full and the paragraph content still has remaining content, it will perform line break processing. When a line of typesetting is completed, the precise position and space occupied by the line in the content column of the layout file are determined based on the line content height and paragraph line height style. If the remaining space in the content column is insufficient, the paragraph will be paginated. At this stage, the logic of tabs, character spacing, character scaling, etc. is also processed.

[0075] 4.2 Table Composer

[0076] The table typesetter is used to create a corresponding table structure in the layout document according to the definition of the table in the flow document, and includes the following steps:

[0077] (1) Determine the columns of the table to establish a two-dimensional array, and determine the specific row and column position of the table in the table based on the cross-row and cross-column properties of each table;

[0078] (2) Calculate the width of each table and calculate its content column based on the table line width and inner margin;

[0079] (3) Start the content column typeset to typeset and calculate the table content. The height of each table is determined by the table content typeset calculation result and the row height attribute of the row, and then the height of the row is determined. Then, the height of all tables in the row is unified in reverse.

[0080] (4) After all tables are laid out, the height of the entire table is determined. If the current content column can accommodate the table, it will be placed directly into the content column; otherwise, the table will be paginated.

[0081] In addition to supporting the functions of DOC, DOCX and INDD documents themselves, the present invention also creatively enhances the functions of the important document element table, adds a table footer row function, and supports common functions such as maximum, minimum, average, and sum of table columns that only Excel tables have.

[0082] Similar to a header row, when a table is divided into different pages, a footer row will be displayed on each page. Usually, the table content in the footer row is the result of the numerical calculation of the column in which it is located. This innovation makes DOC, DOCX and INDD documents well applicable to fields such as finance, sales, etc. that require data calculation and display. This function requires the use of a document design plug-in developed based on Microsoft Word and Adobe InDesign, and the table content used for calculation is of numerical type. The present invention stipulates that the header table does not participate in the calculation. Of course, each table in the column can only have one paragraph. If there are more than one paragraph, only the first paragraph is processed.

[0083] 5. Postprocessor

[0084] The post-layout processor is used to perform subsequent processing on the layout memory document after the layout calculations for the entire document are completed. Some content in the layout memory document can only be determined after the layout calculations for the entire document are completed, such as page references (references to the page numbers of other parts of the document), the total number of pages, content alignment, table column calculations, etc. Of course, minor modifications to some content may require adjusting its coordinates, but no line breaks will be processed.

[0085] DOC, DOCX, and INDD all support page number references. For example, after a table of contents entry in a pending document, there's a reference to the page number of the content corresponding to that entry. Clicking the entry redirects the user to that page. The table of contents for a pending document is typically located at the beginning of the document. When the table of contents entry is being typeset, the page on which the corresponding content appears isn't known; this information isn't determined until the entire document is typeset. Therefore, the page number is temporarily referenced using 1. After the document is typeset, the subsequent processor searches for the actual page number corresponding to the entry and replaces the page number after the entry.

[0086] Similarly, DOC, DOCX, and INDD support a reference to the total number of pages, typically in the footer. The total number of pages can only be determined after the entire document is typeset, and subsequent processors are responsible for detecting references to the total number of pages in the document and replacing them accordingly.

[0087] The vertical alignment of the page content and the horizontal alignment of the paragraph content can also be processed in the subsequent processing stage.

[0088] The typesetting post-processor also detects whether each table in the document has column calculations. If so, it collects the values ​​of the corresponding columns (excluding the header row and footer row tables), calculates the values ​​according to the defined calculation method (maximum value, minimum value, average value, sum), and then puts the calculation results into the footer row table.

[0089] The layout document memory model converts the stream document memory model into a layout memory document. At this time, the layout memory document is a layout document stored in the memory.

[0090] 3. Paged2DIFDocumentConverter

[0091] The following table shows the storage format of layout external storage documents:

[0092]

[0093] The layout memory document of the typesetting calculation results can be directly output as a layout file such as PDF / PostScript / PCL, but cannot be output to an external storage device for persistent storage. To persist the typesetting calculation results and achieve multiple outputs with one calculation, the present invention also adopts a layout document storage format called DIFDocument, which is independent of the printing and display device (Device Independent Format).

[0094] like Figure 4 As shown, a general DOC, DOCX and INDD document typesetting method includes the following steps:

[0095] Step S1: Generate a streaming document memory model from the document to be processed through a document parser;

[0096] According to the input document type to be processed, the corresponding document parser DocumentParser, DocParser, DocxParser or InddParser is started to generate a general streaming document memory model StyledDocument.

[0097] Step S2: pre-processing the streaming document memory model: searching and loading external documents referenced in the document to be processed, searching and collecting directory definitions and content items of the document to be processed, and calculating and inserting numerical numbers of paragraphs of the document to be processed.

[0098] S21: Find and load the external documents referenced in the document;

[0099] The document preprocessor searches the full text of the document to be processed, finds and loads external documents referenced in the document to be processed. This method supports referencing other DOC, DOCX, INDD, PDF, and TIFF documents in the main document (the document to be processed). If an external document is found, it will be parsed by the document parser and inserted into the corresponding position of the main document.

[0100] When inserting a referenced external document, select the corresponding document parser such as DocParser, DocxParser, InddParser or loader PDFLoader, TIFFLoader according to the external document type.

[0101] After parsing, the referenced DOC and DOCX / INDD are converted into a StyledDocument. The insertion method of the referenced document (Content-With-Layout or Content-Only) determines how it is inserted into the main document. If Content-With-Layout is used, the section where the main document insertion point is located is split into two sections, and then all pages of the referenced document (for DOC and DOCX, this is the section with the page setup) are inserted. If Content-Only is used (only DOC and DOCX can be referenced in Content-Only mode), all paragraphs or tables in the document are extracted and inserted into the main document.

[0102] You can specify a page range when referencing PDF and TIFF documents. Each selected page will be treated as an independent page after being inserted into the main document.

[0103] S22: Searching and collecting directory definitions and content items. Collecting directory definitions and content items from the document to be processed during the preprocessing phase can cache and improve directory creation efficiency. If content is added after a directory is inserted during document design, the directory must be manually updated to add the new directory items. This is especially true when the present invention involves referencing external documents. After all external documents are loaded, the preprocessor must collect directory items from the entire document to update the document's directory.

[0104] The present invention can flexibly reference external documents. Using a unique document design plug-in, users can conveniently reference another DOC and DOCX, PDF, INDD, or TIFF document in a DOC or DOCX document. When designing a streaming document, a reference to an external document is inserted into the document using the function provided by the document design plug-in. The content of the external document is not loaded into the streaming document during design, but is loaded and typeset by the typesetting engine when the streaming document is typeset and converted into a layout document. This innovation is beneficial for users in large projects to design documents separately according to various sub-functions, and to merge documents conveniently and flexibly when needed. The limitations of the external document reference function are related to the type of document referenced and its position in the main document. If the referenced document is PDF, INDD, or TIFF, it can only be inserted into the main document in units of pages; if the referenced document is DOC or DOCX, the original layout of the referenced document can be maintained during loading (Content-With-Layout mode), or the layout of the referenced document can be discarded and only the content such as paragraphs and tables can be extracted (Content-Only mode). Naturally, DOC and DOCX documents can only be referenced in pure content (Content-Only mode) in tables, headers / footers, and text boxes. This reference relationship to external documents can also be nested, that is, one external document can also reference another external document.

[0105] S23: Calculate and insert the paragraph number. In a flow document, the paragraph number is set on the paragraph in the form of a numbering style. Before the layout memory document model is typeset, the corresponding number or character must be generated according to the numbering style and inserted into the starting position of the paragraph.

[0106] Step S3: linearize the pre-processed streaming document memory model through a document linearization processor to process paragraph styles and character formats;

[0107] The DOM model of the document being processed is not convenient for content location and word recognition during typesetting. Therefore, the DOM structure of the document being processed needs to be linearized during typesetting. For example, section content is converted into a sequence of paragraphs or tables, tables are converted into a sequence of table rows, table rows are converted into a sequence of tables, and paragraphs are converted into a sequence of characters.

[0108] The document linearization processor is used to process the following: (1) analyze each character of all paragraphs in the document to be processed and establish a character model of the paragraph; (2) process the paragraph and character styles, and calculate the specific style of each character (such as font (Songti, Kaiti...), font size, color, background color, whether there is underline or strikethrough, etc.) according to CSS style rules and content style settings; (3) analyze the paragraph character model to perform word recognition and calculate the width and height of each word.

[0109] Step S4: Load and parse the font using the font parser FontReader;

[0110] When converting a paragraph to a character sequence, the specific font used in the document is already known. At this point, the parsed font file can be loaded and used for subsequent character calculations. The main font information used includes character width, height, baseline, and kerning. A font is generally divided into four categories: normal, bold, italic, and bold italic. These four corresponding font files are used. The corresponding font data is selected during calculations based on the bold or italic settings of the character.

[0111] Step S5: Call the document layout controller LayoutController

[0112] Layout controllers are available for Word documents and InDesign documents. Select the appropriate layout controller based on the document type. Document layout primarily includes information such as page size, orientation, margins, headers / footers, different first pages, different odd and even pages, and content display columns.

[0113] Word documents are driven entirely by streaming content and organized into sections. Each section has a specific layout. The Word document layout controller selects the appropriate page layout based on the current page number and then launches the page layout controller to layout the current page. For Word documents, if the body content box is full and there is still content to be included, the Word page layout controller will create a new page in the layout document to continue layouting the remaining content.

[0114] InDesign documents are primarily driven by pages and the content boxes within them. Content boxes contain fluid content, and content boxes on the same or different pages can be connected, allowing content to flow within these connected boxes. Each InDesign page can be associated with a number of base pages, and the final displayed or output page content is a superposition of the content of each InDesign page and its base pages. The InDesign document layout controller scans each document page and its base pages, then launches the page compositor to lay out the current page and its base pages.

[0115] Step S6: Calling the page layout device

[0116] The page layout device includes a Word page layout device and an InDesign page layout device. The processing of the Word page layout device is as follows:

[0117] S61: The Word page layout checks whether the current page has headers and footers. If so, it first typesets the contents of the headers and footers, calculates their height, and then calculates the size of the text display area. If there are no headers and footers, the text display area is equal to the page size minus the margins.

[0118] S62: The Word page layouter dynamically calculates the coordinates, width and height of the content box for the header, footer and body text and creates the content box in the layout document page, and then starts the content box layouter.

[0119] The InDesign page layout process is as follows:

[0120] The InDesign page compositor scans all content boxes on a page and creates content boxes in the layout document page according to the coordinates and width and height specified for each content box, and then starts the content box compositor.

[0121] Step S7: Calling the content box typeset

[0122] The content box compositor examines the current content box, determines the number of columns and the width of each column, creates the content columns within the corresponding layout document content box, associates the content columns with the content display container, and then launches the content column compositor to compositor the current content into the content columns. The content box compositors for Word and InDesign documents use the same logic, thus unifying the typesetting engine processing logic.

[0123] Step S8: Call the content column layout device

[0124] The content column typeset scans the section content. If the current content is a paragraph, the paragraph typeset is started and the process continues to step S9. If it is a table, the table typeset is started and the process jumps to step S11.

[0125] Step S9: Calling the paragraph layout tool

[0126] Based on the paragraph style, such as indentation and leading and trailing spacing, the paragraph display area is calculated, and the line typesetter is started to calculate the line break processing for the paragraph content.

[0127] Step S10: Calling the line typesetter

[0128] A line of space is allocated from the content column at the height of the first word in the current content. Each character is scanned and counted until the line is full or the paragraph ends. If the line is full but there is still content in the paragraph, a line break is performed. When a line is typed, the exact position and space occupied by the line in the layout file content column are determined based on the line content height and paragraph line height style. If there is insufficient space in the content column, the paragraph is paginated. This stage also handles logic such as tabs, character spacing, and character scaling.

[0129] Among them, the factors that affect line breaks mainly include spaces, hyphens, punctuation marks, non-breaking spaces, etc. For Western languages, spaces are the basis for identifying words. If the paragraph is set not to allow line breaks at hyphens, it is necessary to break at spaces. Otherwise, check whether the current word has an explicit hyphen. If not, look for the implicit hyphen of the current word in the dictionary table. If there is an explicit or implicit hyphen, break at the hyphen closest to the end of the line; no matter how many spaces there are at the end of the line, they will be ignored (that is, they will not occupy line space); generally speaking, punctuation marks cannot appear at the beginning of a line; line breaks cannot be made at non-breaking spaces. According to this rule, the line typeset detects whether the current character can break at the current character. If not, it searches for a line break point from the end of the line to the beginning of the line. If no line break point is found until the beginning of the line, all rules are ignored and the line breaks are made directly at the current character. The pseudo code of the algorithm is as follows,

[0130]

[0131]

[0132]

[0133] Each time the line layout device is called, a line of content is generated in the layout memory document and placed in the content column of the layout memory document. The paragraph layout device calls the line layout device in a loop until the content of the paragraph ends.

[0134] Step S11: Calling the table layout tool

[0135] Create the corresponding results in the layout memory document according to the definition of the table in the flow document. The processing includes the following steps:

[0136] (1) Determine the number of columns in the table, create a two-dimensional array, and determine the specific row and column position of each table in the table based on the cross-row and cross-column properties of each table;

[0137] (2) Calculate the width of each table and calculate its content column based on the table line width and inner margin;

[0138] (3) Start the content column typeset to typeset and calculate the table content. The height of each table is determined by the table content typeset calculation result and the row height attribute of the row, and then the height of the row is determined. Then, the height of all tables in the row is reversed to unify the height. After all tables are typeset, the height of the entire table is determined.

[0139] (4) If the current content column can accommodate the table, put it directly into the content column; otherwise, perform paging of the table.

[0140] In the streaming document model, a table contains one or more rows, each row contains one or more tables, and each table can span one or more rows and one or more columns. The total number of rows and columns in a table is fixed. However, because tables span rows and columns, determining which column a table belongs to requires complex logic. The code is as follows.

[0141]

[0142]

[0143]

[0144] Among them, when the content has filled up a page (or a column) and there is still some content left, paging is required. The main factors to be considered for paging include paragraph orphan control, line continuity, paragraph continuity settings, and whether the table rows can be split. If the paragraph needs to be controlled as orphan, the first line of the paragraph cannot be left alone on the previous page, but needs to be pulled to the next page. The last line of the paragraph cannot be placed alone at the beginning of a page, but needs to be pulled down a line from the previous page; if the paragraph is set to line continuity, the page cannot be broken from the middle of the paragraph, and all the lines of the paragraph on the previous page need to be pulled to the next page; if the paragraph is set to be continuous, the paragraph and the following content (which can be a paragraph or a table) need to be placed on the same page. When the typesetting detects that such a paragraph is at the end of a page, all the lines of the paragraph need to be pulled to the next page. When a page break occurs on a table, it is necessary to consider whether the table row can be split. The header row cannot be split. If the content row cannot be split, the current content row will be moved to the next page. At this time, it is necessary to check whether the previous row is the header row. If not, it is also necessary to check whether the previous row should remain connected to the current row. If so, continue to the previous row and follow this rule until a page break is found. If no page break is found, the entire table is moved to the next page. The paragraph and table paging detection logic is executed repeatedly until a page break point is found. If no page break point is found on the entire page, all rules are ignored and the page is broken directly at the full position of the current page.

[0145] The pseudo code of the paging algorithm is as follows:

[0146]

[0147]

[0148] It's important to note that due to orphan line control, once a page is full, it's unknown how many lines a paragraph will have on the next page. Therefore, the paging process is designed to be triggered when the first paragraph of the next page is typed. That is, when the first paragraph of the next page is typed, a paging control is performed on the previous page to check if there is any content that needs to be moved to the next page. If the first line of the next page is an orphan line and the paragraph contains content on the previous page, the line is moved from the previous page to the next page, and then the paging point on the previous page is searched again.

[0149] The table layouter creates a corresponding layout document table row and column structure based on the style and content of the table in the flow document and places it into the layout document. Each table can be thought of as a content column, and the table layouter calls the content column layouter to layout each table.

[0150] The core typesetting engine provided by the present invention repeats typesetting calculations for all contents of the document until the typesetting calculations for the entire document are completed.

[0151] Step S12: Calling the typesetting post-processor

[0152] This step calculates the total number of pages in the document, replaces page number references, aligns content (such as vertical alignment of pages and horizontal alignment of paragraph lines), and calculates table columns, and adjusts the coordinates of some content.

[0153] Step S13: Calling the layout document converter

[0154] In order to persist the typesetting calculation results and realize multiple outputs of one calculation, a document format (DIFDocument) that is independent of the printing and display device and can be converted between internal and external storage media is adopted to persist the typesetting results.

[0155] The universal DOC, DOCX and INDD document typesetting engine and method can perform typesetting calculations on mainstream office documents DOC, DOCX and Adobe book publishing and magazine layout documents INDD. The typesetting calculation results can be persistently saved as files that are independent of specific output formats or display devices, and can also be directly output to mainstream layout file formats such as PDF, PostScript, PCL, etc.

Claims

1. A universal DOC, DOCX and INDD document typesetting engine, characterized by: It includes a streaming document model and a layout memory document model, which are respectively used to generate a streaming document memory model from a document to be processed, and to form a layout memory document from the streaming document memory model; the streaming document model includes a document parser, a document preprocessor, a document linearization processor and a font parser, and the operations performed on the document to be processed in sequence are reading the document, loading referenced external documents, processing paragraph styles and character formats, and loading fonts used in the document; the layout memory document model includes a layout controller, a page layout device, a content box layout device, a content column layout device and a layout post-processor, which processes the streaming document memory model in sequence to form a final layout memory document; The document preprocessor is used to search the full text of the document to be processed, find and load the external documents referenced in the document to be processed; for the external documents, it is necessary to find and collect the directory definition and content items of the external documents; at the reference of the external document, calculate and insert the numerical number of the paragraph of the referenced external document; The content box layout device is used to check the number of columns of the current content box and the width of each column, create a content column in the corresponding layout document content box, associate the content column with the content display container, and then start the content column layout device to layout the current content into the content column; the content column layout device is used to scan the content of the section in the streaming document memory model, if the current content is a paragraph, start the paragraph layout device, if it is a table, start the table layout device; The paragraph typeset starts calling the line typeset. The line typeset applies for a line of space from the content column at the height of the first word of the current content, and scans and calculates each character until the line space is full or the paragraph content ends. If the line space is full and there is still content left in the paragraph, a line break is performed. When a line is typed, the exact position and space occupied by the line in the content column of the layout file are determined based on the line content height and the paragraph line height style. If there is insufficient space left in the content column, the paragraph is paginated. Each time the line typeset is called, a line of content in the layout memory document is generated and placed in the content column of the layout memory document. The paragraph typeset calls the line typeset cyclically until the paragraph content ends. The document parser is used to read various parts of the content of the document to be processed, including parsing the layout definition and style definition in the document to be processed, as well as parsing the content and format of the document to be processed, and then generating the corresponding layout, style and content elements in the streaming document model StyledDocument. According to the attribute indication of the document to be processed, the corresponding DOC parser, DOCX parser or INDD parser is selected.

2. The universal DOC, DOCX and INDD document typesetting engine according to claim 1, characterized in that: The document linearization processor includes the following contents: (1) analyzing each character of all paragraphs in the document to be processed and establishing a character model of the paragraph; (2) processing paragraph and character styles, and calculating the specific style of each character based on CSS style rules and content style settings, wherein the specific style includes font, font size, color, background color, and whether there is underline or strikethrough; (3) analyzing the paragraph character model to perform word recognition and calculate the width and height of each word.

3. The universal DOC, DOCX and INDD document typesetting engine according to claim 1, characterized in that: The layout controller is used to start the core typesetting function of the streaming document memory model, which includes a Word document layout controller and an InDesign document layout controller; the Word document layout controller selects the corresponding page layout according to the current page number, and then starts the page layout device to typeset the current page; the InDesign document layout controller scans each page of the document and its basic pages, and then starts the page layout device to typeset the current page and its basic pages of the InDesign document.

4. The universal DOC, DOCX and INDD document typesetting engine according to claim 1, characterized in that: The page layouter includes a Word page layouter and an InDesign page layouter; the Word page layouter is used to check whether the current page has a header and footer. If so, the content of the header and footer is layouted first, the height of the header and footer is calculated, and then the size of the displayable area of ​​the text is calculated; the Word page layouter dynamically calculates the coordinates, width and height of the content box for the header and footer and the text, and creates a content box in the layout document page, and then starts the content box layouter; the InDesign page layouter scans all content boxes in a page, and creates a content box in the layout document page according to the coordinates and width and height specified by each content box, and then starts the content box layouter.

5. The universal DOC, DOCX and INDD document typesetting engine according to claim 1, characterized in that: The table typeset is provided with a footer row function, which supports calculation functions for table columns, including maximum value, minimum value, average value and sum; when a table is divided into different pages, the footer row will be displayed on each page, and the table content of the footer row is the result of the numerical calculation of the column in which it is located, and the header table does not participate in the calculation. Each table in the column can only have one paragraph. If there is more than one paragraph, only the first paragraph is processed.

6. A general DOC, DOCX and INDD document typesetting method comprising the following steps: S1: Generate a streaming document memory model through the document parser. S2: Preprocessing the streaming document memory model: Finding and loading external documents referenced in the document to be processed, finding and collecting the directory definition and content items of the document to be processed, and calculating and inserting the numerical numbers of the paragraphs of the document to be processed. The external documents are parsed by the document parser and inserted into the corresponding position of the main document. S3: The preprocessed streaming document memory model is linearized through the document linearizer to process paragraph styles and character formats; S4: Font loading and parsing through the font parser; S5: Selecting a corresponding layout controller according to the document type of the input document, wherein the Word document layout controller selects a corresponding page layout according to the current page number, and then starts the page layout controller to typeset the current page; the InDesign document layout controller scans each page of the document and its base page, and then starts the page layout controller to typeset the current page and its base page; S6: Calling the page layout: The Word page layout dynamically calculates the coordinates, width and height of the content boxes for the header, footer and body text and creates the content boxes in the layout document page; the InDesign page layout scans all content boxes in a page and creates content boxes in the layout document page according to the coordinates, width and height specified for each content box; S7: Call the content frame typeset: used to check the number of columns of the current content frame and the width of each column; S8: Call the content column layout device; scan the section content. If the current content is a paragraph, start the paragraph layout device and continue to step S9. If it is a table, start the table layout device and jump to step S11. S9: Calling the paragraph layout device: Calculating the paragraph display area based on the paragraph style, and starting the line layout device to calculate the line break processing of the paragraph content; S10: calling the line typeset: applying for a line of space from the content column with the height of the first word of the current content, scanning and calculating each character until the line space is full or the paragraph content ends, if the line space is full and there is still content in the paragraph, then line break processing is performed, when a line of typesetting is completed, the precise position and space occupied by the line in the content column of the layout file are determined according to the line content height and the paragraph line height style, if there is insufficient space in the content column, then the paragraph is paged; each time the line typeset is called, a line of content in the layout memory document is generated and placed in the content column of the layout memory document, and the paragraph typeset is called cyclically until the content of the paragraph ends; S11: Calling the table layout device: Based on the style and content of the table in the flow document, a corresponding layout document row and column structure is created and placed in the layout document. Each table can be regarded as a content column. The table layout device will call the content column layout device to layout each table. Repeat the layout calculation for all the contents of the document until the layout calculation of the entire document is completed. S12: Calling the typesetting post-processor: calculating the total number of document pages, replacing page number references, content alignment, and table column calculation, and adjusting the coordinates of some content; S13: Calling a layout document converter: using a document format that can be converted between internal and external storage media to persist the layout results.

7. The universal DOC, DOCX and INDD document typesetting method according to claim 6, characterized in that: In step S10, when performing line break processing, factors affecting line break include spaces, hyphens, punctuation marks, and non-breaking spaces; the following three rules are involved: (1) For Western languages, spaces are the basis for word recognition. If a paragraph is set not to allow line breaks at hyphens, it is necessary to break at spaces; (2) Otherwise, check whether the current word has an explicit hyphen. If not, search the dictionary table for the implicit hyphen of the current word. If there is an explicit or implicit hyphen, wrap the line at the hyphen closest to the end of the line. (3) No matter how many spaces there are at the end of a line, they will be ignored. Punctuation marks cannot appear at the beginning of a line. You cannot wrap a line at a non-breaking space; According to this rule, the line typesetter checks whether a line break can be made at the current character. If not, it searches for a line break point from the end of the line toward the beginning of the line. If no line break point is found even at the beginning of the line, it ignores all rules and directly breaks the line at the current character.

8. The universal DOC, DOCX and INDD document typesetting method according to claim 6, characterized in that: In step S11, the table layout device creates a corresponding layout document table row and column structure according to the style and content of the table in the flow document, and places it into the layout document, including the following steps: (1) Determine the number of columns in the table, create a two-dimensional array, and determine the specific row and column position of each table in the table based on the cross-row and cross-column properties of each table; (2) Calculate the width of each table and calculate its content column based on the table line width and inner margin; (3) Start the content column typeset to typeset and calculate the table content. The height of each table is determined by the table content typeset calculation result and the row height attribute of the row, and then the height of the row is determined. Then, the height of all tables in the row is reversed to unify the height. After all tables are typeset, the height of the entire table is determined. (4) If the current content column can accommodate the table, put it directly into the content column, otherwise the table is paginated; Because of the control of orphan lines in paragraphs, when a page is full, it is not known how many lines of this paragraph will be on the next page. Therefore, the paging process is designed to be triggered when the layout of the first paragraph of the next page is completed. That is, when the layout of the first paragraph of the next page is completed, paging control is performed on the previous page to detect whether there is content that needs to be moved to the next page; if the first line of the next page is an orphan line and the paragraph it belongs to has content on the previous page, then move one line from the previous page to the next page, and then find the paging point of the previous page.

Citation Information

Patent Citations

  • Electronic document generating and displaying method and apparatus

    CN104239305A

  • method and device for converting a streaming file in a DOC / DOCX format into a format file in an OFD format

    CN109829139A