Jexi Design (4) Document Class Design

zhaozj2021-02-16  49

Document class Document needs to solve three problems:

1. How to store document data:

In order to indicate the hierarchy of the document rather than the display structure, use the Composite mode, borrow the GOF design, define the interface GLYPH, abstract the following classes:

Char class: Represents a character. Picture class: Represents a picture. PARAGRAPH: Paragraphs consisting of several CHAR and Picture, with ArrayList: Glyphs Storage CHAR and PICTURE.

The Document class only needs to keep an ArrayList: Paragraphs to access all Paragraphs, thereby accessing any char or Picture. The level is as follows:

The above solves the problem of how the basic data of the document is saved in memory.

2. How to display the document:

For graphic mixing, to implement "see you see", you will need to type the above basic data according to a certain format, and finally renders them into the display area of ​​the window. For typography, abstract the following class:

ROW class: Represents a row, each ROW object knows that it contains the CHAR and Picture objects. Page Class: Represents a page, each Page object can know that it contains the ROW object.

The hierarchical structure is as follows:

Such the Document class only needs to keep an ArrayList: Pages you can know which pages it contains and displays, each Page object contains an ArrayList: ROWS, so VIEW can display the Page and Row you need to display.

3. How to typeset:

The user's insertion or deletion operation will directly lead to the modification of the Paragraph of the basic data. At this time, it is necessary to start re-typography from the right place, which is to regenerate the Page, Row object, or modify the existing page, the ROW object.

The process of typography is: Starting from the affected Paragraph, regenerate the necessary ROW according to the typesetting algorithm, then assemble the new Page object according to the generated ROW:

The above is my basic idea, mainly to divide the document data into two categories: First, the basic data, the logical structure used for the document, does not contain any display logic; the second is the display model, according to the logical structure of the document, the typesetting algorithm, generate documentation The display model, so that new basic elements can be added, such as text boxes, such as text boxes, without affecting the display model, display models can also add new elements such as Column implementing columns without affecting logical models, welcome BLogger evaluation!

转载请注明原文地址:https://www.9cbs.com/read-15421.html

New Post(0)