Skip to content

Commit

Permalink
fix: allow decimal viewport dimensions in fixed-layout
Browse files Browse the repository at this point in the history
The spec only says dimensions must be a "positive number" (or keyword), it does not specifically forbid decimal values.

Fix #1481
  • Loading branch information
rdeltour committed Apr 22, 2023
1 parent b81a77d commit fc5e360
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 2 deletions.
Expand Up @@ -12,8 +12,8 @@

public class ViewportMeta
{
private static Pattern VIEWPORT_HEIGHT_REGEX = Pattern.compile("\\d+|device-height");
private static Pattern VIEWPORT_WIDTH_REGEX = Pattern.compile("\\d+|device-width");
private static Pattern VIEWPORT_HEIGHT_REGEX = Pattern.compile("\\d+(\\.\\d+)?|device-height");
private static Pattern VIEWPORT_WIDTH_REGEX = Pattern.compile("\\d+(\\.\\d+)?|device-width");

public static ViewportMeta parse(String string, ErrorHandler errorHandler)
{
Expand All @@ -26,6 +26,7 @@ public static boolean isValidProperty(String name, String value)
switch (Preconditions.checkNotNull(name))
{
case "width":

return VIEWPORT_WIDTH_REGEX.matcher(value).matches();
case "height":
return VIEWPORT_HEIGHT_REGEX.matcher(value).matches();
Expand Down
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=600.999,height=1200.5" />
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<head>
<meta charset="utf-8"/>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="q">NOID</dc:identifier>
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
<meta property="rendition:layout">pre-paginated</meta>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
@@ -0,0 +1 @@
application/epub+zip
5 changes: 5 additions & 0 deletions src/test/resources/epub3/08-layout/layout.feature
Expand Up @@ -214,6 +214,11 @@ Feature: EPUB 3 — Layout Rendering Control
When checking EPUB 'content-fxl-xhtml-viewport-valid'
Then no errors or warnings are reported

@spec @xref:sec-fxl-content-dimensions
Scenario: Verify a fixed-layout XHTML document with non-integer viewport dimensions
When checking EPUB 'content-fxl-xhtml-viewport-float-valid'
Then no errors or warnings are reported

@spec @xref:sec-fxl-content-dimensions
Scenario: Verify a fixed-layout XHTML document with a valid viewport with whitespace
When checking EPUB 'content-fxl-xhtml-viewport-whitespace-valid'
Expand Down

0 comments on commit fc5e360

Please sign in to comment.