Modern browsers use a multi-stage document processing pipeline to transform a representation of a web page or other document made up of a markup language document (e.g., a document expressed in HyperText Markup Language (“HTML”), eXtensible Markup Language (“XML”), eXtensible Application Markup Language (“XAML”), and/or Scalable Vector Graphics (“SVG”) and a formatting resource (e.g., a Cascading Style Sheet (“CSS”)) into a visual representation of the document shown on a display device.
In conventional ones of such browsers, visual presentation logic responsive to conditions under which the document will be displayed is evaluated at an early stage of the document processing pipeline, such as when a deserialized version of the formatting resource (e.g., a Cascading Style Sheet Object Model) is generated from the formatting resource. Such “formatting-time” conditions are expressed in terms of logical pixels used to do browser layout; logical pixels are sometimes called “CSS pixels,” and differ from the physical pixels of the display device with respect to which the final visual representation of the document is ultimately generated. For example, a formatting-time condition based on a CSS @media query can cause a formatting rule, such as one to establish a particular background color, to be applied only if the width of the browser window is no more than 400 CSS pixels (“400 px”).
SUMMARY
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the Detailed Description. This summary is not intended to identify key factors or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
A facility for rendering a document is described. The facility performs layout for the document. After performing layout for the document, the facility performs rendering for the document. The rendering performed by the facility for the document includes evaluating at least one condition specified in connection with authoring the document.
The inventors have recognized that the conventional approach of evaluating visual presentation logic early in the document processing pipeline—such as at formatting-time—has significant disadvantages. A first disadvantage is that if, during display of the rendered document, state changes in such a way as to alter satisfaction of one of the conditions, a significant portion of the document processing pipeline must be repeated for the document to reflect the change in satisfaction of the condition, which can consume considerable processing resources, and/or introduce significant latency in reflecting the change in the rendered document. For example, a change in the width of the browser window can alter satisfaction of a condition that is based on the width of the browser window.
A second disadvantage is that, early in the document processing pipeline, dimensions of the document and its contents are expressed exclusively in terms of CSS pixels, making it impossible to at that point in the pipeline compare such dimensions to dimensions expressed in physical pixels.
In order to overcome the disadvantages discussed above, the inventors have conceived and reduced to practice a software and/or hardware facility (“the facility”) for including conditions with respect to a document that are evaluated upon rendering of the document. In various examples, these can be conditions that determine whether document fragments are included in the visual representation generated for the document as well as conditions that determine whether particular formatting attributes are applied to particular document fragments. These conditions can compare dimensions within the document to numbers of physical pixels specified in the conditions.
In some examples, the facility permits conditions that involve comparisons of dimensions expressed in physical pixels to be imposed on groups of formatting attributes specified for styles, such as CSS styles, established for various classes of markup entities and their corresponding display fragments.
For example, in a document where a background image is to be included only when display of the document is zoomed in, the visualization of the background image is conditioned on the zoom level being greater than a threshold level.
In some examples, the facility implements such conditions on visualization of a fragment by establishing a non-display formatting attribute in a style specified for the class to which the fragment corresponds where the non-display attribute is established subject to a condition that is the logical inverse of the condition for including the fragment. Here, a non-display attribute for a class corresponding to the image can be conditioned on the physical window width being smaller than a threshold number of physical pixels, while a non-display attribute for a class corresponding to the text can be conditioned on the physical window width being larger than or equal to the threshold number of physical pixels. If, during display of the document, a user alters the window size in such a way that its physical width passes the threshold number of physical pixels, the non-display attributes are inverted between the display fragments corresponding to the two classes at the rendering stage, causing the text and image to be exchanged.
As another example, a document containing a cartographic map may be designed to be responsive to a user-controlled zoom level. For each available zoom level, a set of map tiles corresponding to the zoom level adequate to fill the a map region of the window can be included, subject to a condition that the current zoom level corresponds to the zoom level of the tiles. At render time, only the set of tiles corresponding to the current zoom level is visualized. If, during display of the document, a user alters the zoom level, a different set of tiles corresponding to the new zoom level is visualized at the rendering stage.
As a further example, in a document containing a schematic diagram, conditions can be included that prevent lines making up the diagram within a bounded range of thicknesses between 1 physical pixel and 10 physical pixels.
By evaluating these conditions during the rendering stage of the render pipeline, the facility (1) makes it possible to impose conditions expressed in terms of dimensions measured in physical pixels, so that the conditions can address the way the document is displayed on the display device, and (2) can respond to state changes that alter the outcome of conditions in an efficient way that obviates repeating significant portions of the render pipeline processing.
Those skilled in the art will appreciate that the steps shown in
Table 1 below contains sample source code for a sample document rendered by the facility in some examples.
Lines 1-21 define the document. Lines 5-14 specify CSS formatting information. In particular, lines 8-12 define a style for an “state” class of elements. This class definition contains two render-time conditions for determining whether elements of the state class have a background. The first render-time condition on line 8 is satisfied where the zoom level is relatively low, reflecting that display of the document is zoomed relatively far out. Where this condition is satisfied, elements of the state class have no background. The second render-time condition on line 11 is satisfied where the zoom level is relatively high, reflecting that display of the document is zoomed in relatively far. Where this condition is satisfied, elements of the state class have a background corresponding to an image containing a state border. In line 18, an element made up of the text “WASHINGTON” is attributed the state class. Accordingly, this element will have the specified image as a border when the document is zoomed in relatively far, and won't have a border when the document is zoomed out relatively far.
In various embodiments, the facility supports the use of a variety of measures in its render-time conditions including, for example, fragment width, fragment height, window width, window height, device width, device height, device orientation, device aspect ratio, device pixel ratio, zoom factor, and transforms.
In some examples, a computer-readable medium having contents adapted to cause a computing system to perform a process for rendering a document is provided. The process comprises: performing layout for the document; and after performing layout for the document, performing rendering for the document, wherein performing rendering for the document comprises evaluating at least one condition specified in connection with authoring the document.
In some examples, a computing system adapted to render a document is provided. The computing system comprises: a layout engine configured to perform layout for the document; and a renderer configured to, after the layout engine performs layout for the document, perform rendering for the document, wherein the rendering performed for the document by the renderer comprises evaluating at least one condition specified in connection with authoring the document.
In some examples, a computer-readable medium storing a data structure is provided. The data structure comprises: one or more entries each corresponding to a style for displayable fragments, each entry at least one style attribute, each of at least one of the entries specifying, for a selected one or more its style attributes, an application condition specified on the application of the selected style attributes, the application condition being expressed in terms of a number of pixels of a physical display device on which displayable fragments are to be displayed, such that the contents of the data structure are usable to determine whether each of the selected style attributes should be applied to displayable fragments.
It will be appreciated by those skilled in the art that the above-described facility may be straightforwardly adapted or extended in various ways. While the foregoing description makes reference to particular approaches to implementation, the scope of the invention is defined solely by the claims that follow and the elements recited therein.
This application claims the benefit of U.S. Provisional Application No. 62/163,331, filed May 18, 2015, and entitled “DOCUMENT FRAGMENTS QUALIFIED BY CONDITIONS EVALUATED ON RENDERING,” which is incorporated herein in its entirety by reference.
Number | Date | Country | |
---|---|---|---|
62163331 | May 2015 | US |