Dynamically displaying online documents based on document object attributes

Embodiments of the present disclosure provide a method and apparatus for online displaying a document. In one embodiment of the present disclosure, there is provided a method for online displaying a document, comprising: extracting a plurality of data objects from the document; obtaining sizes of corresponding data objects among the plurality of data objects by constructing a document object model associated with the plurality of data objects; generating a layout repository based on the sizes; and rendering the plurality of data objects based on the layout repository, so as to online display the document. In one embodiment of the present disclosure, there is provided an apparatus for online displaying a document. By means of the method and apparatus of the present disclosure, the efficiency of online displaying documents can be increased and thereby user experience can be improved.

RELATED APPLICATIONS

The subject application claims the priority of Chinese Patent Application Serial No. 201410068034.4, filed on 27 Feb. 2014, the entire content of which is herein incorporated by reference.

FIELD

Various embodiments of the present disclosure relate to document displaying, and more specifically, to a method and apparatus for online displaying a document.

BACKGROUND

With the development of computer technology, besides data transmission, more and more powerful functions can be provided via computer networks. For example, cloud computing is a model of service delivery for enabling convenient, on-demand network access to a shared pool of configurable computing resources. At this point, a user does not have to buy a high-performance computing device and install various application programs on the computing device to meet his/her demand, but can obtain needed resources and services via cloud.

For example, the user does not have to install a document editor on a local computer, but rather can view and edit documents using a browser through an online document editor provided by a network service provider. In addition, with the miniaturization and diversity tendency of computing devices, more and more users tend to use portable computing devices (such as tablet PCs, smart phones, personal digital assistants, etc.) for viewing and editing documents. Since hardware configuration of portable computing device is usually low, research has been directed toward providing online document editors for use via portable computing devices.

Though browser-based online document editors have been developed so far, their displaying efficiency tends to be low and they may not be able to display document content at a user-desired speed, and such a long delay during document displaying may lead to bad user experience.

SUMMARY

According to some implementations of the present disclosure, systems and methods for online displaying documents efficiently may be provided, which may be compatible with existing browser-based online text editors so as to achieve high-efficiency online displaying on various computing devices (especially portable computing devices).

In one embodiment of the present disclosure, there is provided a method for online displaying a document, including: extracting a plurality of data objects from the document; obtaining sizes of corresponding data objects among the plurality of data objects by constructing a document object model (DOM) associated with the plurality of data objects; generating a layout repository based on the sizes; and rendering the plurality of data objects based on the layout repository, so as to online display the document.

In one embodiment of the present disclosure, a data object among the plurality of data objects may be uniquely identified based on text content and style associated with the data object.

In one embodiment of the present disclosure, obtaining sizes of corresponding data objects among the plurality of data objects by constructing a document object model associated with the plurality of data objects may include: constructing the document object model based on text content and style associated with the plurality of data objects; and using a browser to render the document object model so as to obtain sizes of corresponding data objects among the plurality of data objects.

According to another implementation, a computer program product may include a non-transitory computer readably storage medium having a plurality of instructions stored on it. When executed by a processor, the instructions may cause the processor to perform operations including extracting a plurality of data objects from a document. Instructions may also be included for obtaining sizes of corresponding data objects among the plurality of data objects by constructing a document object model associated with the plurality of data objects. Instructions may also be included for generating a layout repository based on, at least in part, the sizes. Instructions may further be included for rendering the plurality of data objects based on, at least in part, the layout repository, so as to online display the document.

In one embodiment, a data object among the plurality of data objects may be uniquely identified based on, at least in part, text content and style associated with the data object.

In one embodiment, the instructions for rendering the plurality of data objects based on, at least in part, the layout repository so as to online display the document may include instructions for rendering the plurality of data objects line by line according to page width for online displaying the document and based on, at least in part, the layout repository, so as to online display the document.

In one embodiment, the style may include at least any one of: font, font size, bold, italics, superscript, subscript, heading, and text. In an embodiment, the data object may be a text object.

According to a further implementation, a computing system may include a processor and a memory device coupled with the processor. The processor may be configured for extracting a plurality of data objects from a document. The processor may also be configured for obtaining sizes of corresponding data objects among the plurality of data objects by constructing a document object model associated with the plurality of data objects. The processor may also be configured for generating a layout repository based on, at least in part, the sizes. The processor may further be configured for rendering the plurality of data objects based on, at least in part, the layout repository, so as to online display the document.

In one embodiment, a data object among the plurality of data objects may be uniquely identified based on, at least in part, text content and style associated with the data object.

In one embodiment, the processor configured for rendering the plurality of data objects based on, at least in part, the layout repository so as to online display the document may be further configured for rendering the plurality of data objects line by line according to page width for online displaying the document and based on, at least in part, the layout repository, so as to online display the document.

In one embodiment, the style may include at least any one of: font, font size, bold, italics, superscript, subscript, heading, and text. In one embodiment, the data object may include a text object.

By means of the method and apparatus as described in the present disclosure, the efficiency of online displaying documents may be increased, and user wait time may be reduced and thereby user experience is improved.

DETAILED DESCRIPTION

Characteristics are as follows:

Service Models are as follows:

Deployment Models are as follows:

In one embodiment of the present disclosure, a solution for online displaying documents according to various embodiments of the present disclosure may be implemented at workloads layer66, so that in the cloud computing environment tools for online displaying documents may be provided to the user whereby the user can conveniently view and edit documents by way of a browser, for example, in a situation in which no document editor is installed in the user's local computer. The application environment of the present disclosure has been illustrated above; those skilled in the art should understand the embodiments of the present disclosure may be implemented under any other type of computing environment that is currently known or to be developed in future.

In the data displaying field, a conventional document editor (e.g., document editor installed on a computer) may directly obtain a size of each word in a to-be-displayed document by calling an application programming interface (API) of the operating system (i.e., with how many pixels the word is displayed in a page). However, unlike an implementation mode in the conventional document editor, in online displaying a document in a browser no API may exist and/or be available via which the size of each word in the to-be-displayed document can be obtained directly. In some such situations, the size can only be obtained by means of a document object model.

In some solutions for online displaying documents in a browser, since the browser renders page content based on the document object model, the size of the document's each word in the displaying page may be obtained and then displayed.

To obtain size of each word, the size of each word may be calculated based on the document object model one word after another in an order of words in the document. A storage space may be arranged to cache calculated sizes, so that size of a word may not need to be re-calculated when the same word is rendered once again. However, this displaying mode may provide a relatively low-efficiency and might lead to displaying delay, which may be more conspicuous for portable computing devices with limited hardware resources.

The present disclosure may provide solutions for online displaying documents that may provide improved efficiency and/or improved user experience. Consistent with embodiments of the present disclosure, the length of each word in a document may be obtained by a pre-processing step before a rendering step, so in the rendering step a corresponding word may be rendered directly based on the obtained length in the pre-processing step, rather than the size of the word being obtained based on the document object model each time before rendering.

For example,FIG. 4schematically shows an architecture diagram400of an implementation for online displaying a document according to one embodiment of the present disclosure. As shown inFIG. 4, a document410represents a to-be-displayed document, and each data object and size thereof may be extracted from document410and the corresponding size may be stored in a layout repository420. Subsequently, the document may be displayed online based on data in layout repository420(as shown by a display page430).

Note throughout the context of the present disclosure, data objects may refer to text objects in a document. For example, headings, text, words, punctuations, etc. in the document can be called text objects. For other type of data object appearing in the document, this object's size may be obtained using other approaches. For example, an image object that has a fixed size (e.g., resolution) can be displayed with the fixed size. Table objects may be divided into fixed-size tables and variable-size tables. For a fixed-size table, the table may be displayed directly with the fixed size. For a variable-size table, however, the table's variable size may depend on size of a text object in the table. So, first size of the text object may be determined and then size of the table object may be determined, based on the method as disclosed by the present disclosure. In addition, spaces, punctuations and other special characters may fall within the meaning of text objects in the present disclosure and thus can be displayed using the method of the present disclosure.

In one embodiment of the present disclosure, there is provided a method for online displaying a document, including extracting a plurality of data objects from the document. The method may also include obtaining sizes of corresponding data objects among the plurality of data objects by constructing a document object model associated with the plurality of data objects. The method may also include generating a layout repository based on the sizes. The method may further include rendering the plurality of data objects based on the layout repository, so as to provide an online display the document.

FIG. 5schematically shows a flowchart500of a method for online displaying a document according to one embodiment of the present disclosure. In step S502, a plurality of data objects may be extracted from the document. Those skilled in the art will appreciate that a plurality of data objects may be extracted from a document based on various methods known in the prior art. In the context of the present disclosure, data objects may include words or symbols in a document. Suppose a document includes “Hello World!”, that document may be considered to include 4 objects, which are “Hello”, “space”, “World” and “!”.

For documents written in different languages, data objects may have different meanings. For example, in a document written in Chinese, it may be considered each Chinese character may be a data object; in a document written in English or French, it may be considered each word may be an object, etc. Since a browser supports a multilingual function, the technical solution of the present disclosure may also support online displaying a document in a multilingual environment.

Next in step S504, sizes of corresponding data objects among the plurality of data objects may be obtained by constructing a document object model associated with the plurality of data objects. It should be noted that, since content displayed in the browser is implemented via a document object model, first a document object model associated with to-be-displayed content may be constructed, and then it can be learned, based on the model, with how many pixels a corresponding data object will be displayed in the browser. In the context of the present disclosure, size of a data object refers to the data object's size when being displayed online, i.e., number of pixels occupied by the data object in one row.

Optionally, before constructing the document object model, first the plurality of data objects being extracted may be filtered. By filtering duplicated data objects, the number of data objects may be reduced and the processing efficiency may be increased. Note for English, differentiation may be made between lower case letters and upper case letters in words, and only where lower case letters and upper case letters in two words are exactly the same as each other, the two words may be regarded as duplicated data objects. For example, “Hello” and “hello” may be regarded as different data objects.

In step S506, a layout repository may be generated based on the sizes. In this step, sizes of various data objects in the document may be saved. Regarding “Hello World!”, for example, a layout repository may be stored using a data structure as shown in Table 1 below.

In step S508, the plurality of data objects may be rendered based on the layout repository, so as to online display the document. In this embodiment, each data object may be displayed sequentially based on the lengths as recorded in Table 1 above. At this point, content “Hello World!” will be displayed in a page, and the content occupies 20+5+25+5=55 pixels.

In one embodiment of the present disclosure, a data object among the plurality of data objects may be uniquely identified based on text content and style associated with the data object. The foregoing example shows a case where various data objects may be differentiated based on only text content of these data objects. Since a data object's size may depend on not only its text content but also its style, data objects may be uniquely identified based on these data objects' text content and style.

In this embodiment, a data object may be represented as a two-tuple (text content, style). In this manner, (Hello, bold) and (Hello, italics) represent different data objects. In the context of the present disclosure, the style may include at least any one of: font, font size, bold, italics, superscript, subscript, heading, and text. Therefore, when the style comprises a plurality of items, the two-tuple may be extended as a multi-tuple. For example, (Hello, bold, 8 size) may represent that Hello is displayed in 8-size font and in bold. Where both text content and style of a data object are taken into consideration, a layout repository may be stored using a data structure as shown in Table 2 below.

To further increase the data processing efficiency, data objects in the document may be grouped according to their style, and subsequently with respect to various data objects in each group among a plurality of resulting groups, sizes of various data objects may be obtained in the above-described manner.

In one embodiment of the present disclosure, obtaining sizes of corresponding data objects among the plurality of data objects by constructing a document object model associated with the plurality of data objects may include dividing the plurality of data objects into a plurality of groups based on style associated with data objects among the plurality of data objects. With respect to each group, a document object model may be constructed associated with at least one data object in the group based on text content and style associated with the at least one data object in the group, thereby constructing the document object model associated with the plurality of data objects. Further a browser may be used to render the document object model, so as to obtain sizes of corresponding data objects among the plurality of data objects.

Note the style may include an inline style. For example, after applying “heading” style to a paragraph, all contents in the paragraph may be in bold type, but still partial contents in the paragraph may be set as italics, and removing the bold attribute. Therefore, before calculating size of an object, final style of the object may be obtained, which may be calculated through style hierarchical relationship and priority arrangement. The calculation process may only consider style that affects size of a data object (such as font, font size, bold, italics, superscript, subscript, heading, and text), but may ignore irrelevant style (such as underline, strikethrough, font color, background color, etc.). Suppose a document's contents read “Hello word1 word2 world”, style of data objects in the document may be represented in a manner below:

Concerning this example, style of “Hello” is as defined by S2, wherein S2 inherits style of S1. In displaying “world,” the style of S2 is overwritten by using custom font size “20.” According to the above method for grouping based on style, “Hello”, “word1” and “word2” may be grouped into a first group, while “world” may be grouped to a second group. At this point, style of “Hello,” “word1” and “word2” is “font-size: 10 pt; bold: true.”

In one embodiment of the present disclosure, obtaining sizes of corresponding data objects among the plurality of data objects by constructing a document object model associated with the plurality of data objects may include constructing the document object model based on text content and style associated with the plurality of data objects. Further, a browser may be used to render the document object model so as to obtain sizes of corresponding data objects among the plurality of data objects.

In this embodiment, text content and style of “Hello,” “word1,” “word2” and “world” obtained using the above method may be used to construct a document object model associated with these data objects. For example, since data objects have been divided into a plurality of groups according to style of the data objects, corresponding processing may be performed with respect to various data objects in each group. Specifically, with respect to data objects “Hello,” “word1” and “word2” in the first group, a document object model may be constructed using a method below.

It should be noted that the above is only intended to provide an example concrete implementation of how to construct a document object model. This example is only for illustration rather than limiting, and those skilled in the art will appreciate that other implementations may be equally utilized. In addition, although illustrated above is a method for constructing a document object model with respect to data objects in a first group only, those skilled in the art will recognized that processing may be performed with respect to data objects in a second group in a similar manner and based on the principle being illustrated.

Dividing the plurality of data objects into groups according to style may serve the purpose of increasing the data processing efficiency; however, this step is not essential but an optional step that may allow for further increasing efficiency. Those skilled in the art will understand that the plurality of data objects extracted from the document may be directly processed, e.g., without grouping these data objects.

Since the pixel number for displaying a data object in the browser is associated with a document object model, where a document object model has been obtained, the document object model may be rendered using the browser, so as to obtain the size of a corresponding data object. Specifically, in one embodiment of the present disclosure, using a browser to render the document object model so as to obtain sizes of corresponding data objects among the plurality of data objects may further include using an application programming interface of the browser to obtain sizes of corresponding data objects among the plurality of data objects.

Sizes of various data objects may be obtained using an application programming interface of the browser. For example, an approach below may be used in some implementations:

As corresponding nodes of the document object model may have been created with respect to each data object, at this point only by calling the browser's application programming interface to obtain size of each node, can the pixel number occupied by each data node displayed in the browser be obtained. In this example, size of each data object may be obtained using existDOMNode.getChild(i).size. Similarly, those skilled in the art will understand that data objects in other group may be processed in a similar manner, e.g., based on the principle of this example.

In one embodiment of the present disclosure, rendering the plurality of data objects based on the layout repository so as to online display the document may include rendering the plurality of data objects line by line according to page width for online displaying the document and based on the layout repository, so as to online display the document.

Since page width for online displaying the document can be obtained and sizes of data objects in the document have been stored in the previous pre-processing step, various data objects in the document may be sequentially placed in each line, so as to online display the document. When free space in one line is not sufficient to accommodate a next data object in the document (i.e., remaining pixels are less than size of the next data object), a new line may be created and the next data object may be placed at the first position of the new line.

FIGS. 6A to 6Billustrate schematic views600A-600B of placing data objects in a page according to one embodiment of the present disclosure.FIG. 6Ashows a schematic view of placing a plurality of data objects in a document at one line one after another. Page width is shown by reference numeral610A; as shown by620A in the ithline, data objects 1 to N are sequentially placed in the ithline, and after placing a data object N, free space in the ithline is not sufficient to accommodate a data object N+1, so a new line (630A in the i+1thline) is created. Next, data object N+1 may be placed at the starting position of the i+1thline. In this manner, each data object in the document may be processed in order.

Note since “space” also belongs to text data, the processing performed to “space” may follow the method of the present disclosure without special processing. In addition, when there is a data object representing “enter”, a new paragraph may be created, and data objects after “enter” may be placed in a new line.

It should be noted that, since the document layout further relates to “align mode”, when displaying the document in the browser, impact of “align mode” on display effect of the document may further be considered. Conventional align modes may include: left, right, center and justify.

In one embodiment of the present disclosure, with respect to at least one data object in a line of the document being displayed online, a difference between the page width and size of the at least one data object may be calculated. The at least one data object may be placed within the line according to the difference and an align mode of the document. In left alignment, the difference between the page width and the plurality of data objects (i.e., space) may be placed at the right of a line, so as to achieve left-align (as shown inFIG. 6A). As how to achieve left-align, it has been described with reference to the example inFIG. 6A, and those skilled in the art will appreciate that right-align and center-align may be accomplished based on the principle being illustrated and described with respect to left-align.

In one embodiment of the present disclosure, placing the at least one data object within the line according to the difference and an align mode of the document may include dividing the difference so as to evenly place the at least one data object within the line.FIG. 6Bschematically shows a block diagram of justify-align. In this example, the difference may be evenly distributed between various data objects so as to achieve justify-align. For example, suppose the page width is 800, the size of each data object is 80, and 9 data objects may be displayed in one line (suppose size of the 10thdata object is greater than 80). At this point a difference between the page width and sizes of all data objects is 800-80×90=80, i.e., 80 pixels are left after placing these 9 data objects in one line one after another. At this point, 80 pixels may be equally allocated to positions between each of the 9 data objects, whereby 9 data objects are displayed in one line in justify-align mode. At this point, a first data object may be displayed at a position of the 1-80 pixels, space is displayed at a position of the 81-90 pixels, a second data object is displayed at a position of the 91-170 pixels, and so on and so forth.

FIG. 7illustrates a schematic view700of a page of an online displayed document according to one embodiment of the present disclosure. According to the method described above, a document may be displayed in the online text editor via the browser. As shown inFIG. 7, a first-level heading of the document is shown in710, which is centered in font size 18; a second-level heading of the document is shown in720, which is centered in font size 14; text of the document is shown in730, which is left-aligned in font size 14.

Using the embodiments described above, by executing the pre-processing step before the rendering step, sizes of various data objects in the document can be obtained fast and efficiently, and corresponding sizes may be stored in the layout repository. In the subsequent rendering step, therefore, size of each data object in the document can be obtained rapidly and efficient drawing (e.g., rendering) achieved. In addition, the data processing efficiency may further be increased by dividing a plurality of data objects into a plurality of groups based on style of these data objects and processing with respect to data objects in each group.

The various embodiments implementing the method of the present disclosure have been described above with reference to the accompanying drawings. Those skilled in the art may understand that the method may be implemented in software, hardware or a combination of software and hardware. Moreover, those skilled in the art may understand by implementing various steps in the above method in software, hardware or a combination of software and hardware, there may be provided an apparatus based on the same concept. Even if the apparatus has the same hardware structure as a general-purpose processing device, the functionality of software contained therein may render the apparatus manifest distinguishing properties from the general-purpose processing device, thereby forming an apparatus of the various embodiments of the present disclosure. The apparatus described in the present disclosure may include several means or modules, the means or modules configured to execute corresponding steps. Upon reading this specification, those skilled in the art may understand how to write a program for implementing actions performed by these means or modules. Since the apparatus is based on the same disclosure concept as the method, the same or corresponding implementation details are also applicable to means or modules corresponding to the method. As detailed and complete description has been presented above, the apparatus is not detailed below.

FIG. 8schematically shows a block diagram800of an apparatus for online displaying a document according to one embodiment of the present disclosure. There is provided an apparatus for online displaying a document, including: an extracting module810configured to extract a plurality of data objects from the document; an obtaining module820configured to obtain sizes of corresponding data objects among the plurality of data objects by constructing a document object model associated with the plurality of data objects; a generating module830configured to generate a layout repository based on the sizes; and a displaying module840configured to render the plurality of data objects based on the layout repository, so as to online display the document.

In one embodiment of the present disclosure, a data object among the plurality of data objects is uniquely identified based on text content and style associated with the data object.

In one embodiment of the present disclosure, obtaining module820may include: a constructing module configured to construct the document object model based on text content and style associated with the plurality of data objects; and a size obtaining module configured to use a browser to render the document object model so as to obtain sizes of corresponding data objects among the plurality of data objects.

In one embodiment of the present disclosure, obtaining module820may include: a grouping module configured to divide the plurality of data objects into a plurality of groups based on style associated with data objects among the plurality of data objects; a first constructing module configured to, with respect to each group, construct a document object model associated with at least one data object in the group based on text content and style associated with the at least one data object in the group, thereby constructing the document object model associated with the plurality of data objects; and a first size obtaining module configured to use a browser to render the document object model, so as to obtain sizes of corresponding data objects among the plurality of data objects.

In one embodiment of the present disclosure, the size obtaining module may further include: a calling module configured to use an application programming interface of the browser to obtain sizes of corresponding data objects among the plurality of data objects.

In one embodiment of the present disclosure, displaying module840may include: a line displaying module configured to render the plurality of data objects line by line according to page width for online displaying the document and based on the layout repository, so as to online display the document.

In one embodiment of the present disclosure, the line displaying module may include: a calculating module configured to, with respect to at least one data object in a line of the document being displayed online, calculate a difference between the page width and size of the at least one data object; and an aligning module configured to place the at least one data object within the line according to the difference and an align mode of the document.

In one embodiment of the present disclosure, the aligning module may include: a dividing module configured to divide the difference so as to evenly place the at least one data object within the line.

In one embodiment of the present disclosure, the style may include at least any one of: font, font size, bold, italics, superscript, subscript, heading, and text.

In one embodiment of the present disclosure, the data object is a text object.