Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public ContentFunctionFactory() {
_functions.add(new PageCounterFunction());
_functions.add(new PagesCounterFunction());
_functions.add(new TargetCounterFunction());
_functions.add(new TargetTextFunction());
_functions.add(new LeaderFunction());
_functions.add(new FsIfCutOffFunction());
}
Expand Down Expand Up @@ -232,6 +233,56 @@ public boolean canHandle(LayoutContext c, FSFunction function) {
}
}


private static class TargetTextFunction implements ContentFunction {
@Override
public boolean isStatic() {
return false;
}

@Override
public String calculate(RenderingContext c, FSFunction function, InlineText text) {
String uri = text.getParent().getElement().getAttribute("href");
if (uri != null && uri.startsWith("#")) {
String anchor = uri.substring(1);
Box target = c.getBoxById(anchor);
if (target != null) {
StringBuilder strBuilder = new StringBuilder();
target.collectText(c, strBuilder);
return strBuilder.toString();
}
}
return "";
}

@Override
public String calculate(LayoutContext c, FSFunction function) {
return null;
}

@Override
public String getLayoutReplacementText() {
return "ABCABC";
}

@Override
public boolean canHandle(LayoutContext c, FSFunction function) {
if (c.isPrint() && function.getName().equals("target-text")) {
List<PropertyValue> parameters = function.getParameters();
if(parameters.size() == 1) {
FSFunction f = parameters.get(0).getFunction();
if (f == null ||
f.getParameters().size() != 1 ||
! f.getParameters().get(0).getStringValue().equals("href")) {
return false;
}
return true;
}
}
return false;
}
}

/**
* Partially implements leaders as specified here:
* http://www.w3.org/TR/2007/WD-css3-gcpm-20070504/#leaders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ private boolean isFunctionAllowed(FSFunction function) {
String name = function.getName();
return name.equals("attr") || name.equals("counter") || name.equals("counters") ||
name.equals("element") || name.startsWith("-fs") || name.equals("target-counter") ||
name.equals("leader");
name.equals("leader") || name.startsWith("target-text");
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
content: url(../../demos/images/flyingsaucer.png) "..." url(../../demos/images/flyingsaucer.png);
}
}
table {
line-height: 100%;
}
table tr {
font-size: small;
}
body {
margin: 10px;
max-width: 340px;
Expand All @@ -37,12 +43,28 @@
background-color: orange;
content: url(../../demos/images/flyingsaucer.png) "..." url(../../demos/images/flyingsaucer.png);
}
#four::after {
content: "Table: " target-text(attr(href)) leader(dotted) target-counter(attr(href), page);
}
#five::after {
content: target-text(attr(href)) leader(dotted) target-counter(attr(href), page);
}
</style>
</head>
<body>
<a id="zero" href="#three" style="display: inline-block;width: 100%;"></a>
<a id="four" href="#table" style="display: inline-block;width: 100%;"></a>
<a id="five" href="#title" style="display: inline-block;width: 100%;"></a>
<div id="one">ONE</div>
<div id="two" data-msg="HELLO"> WORLD</div>
<div id="three" style="page-break-before: always;width: 150%; background-color: gray;color: white;">With images: </div>
<h1 id="title" style="font-size: medium">Title 1</h1>
<table>
<caption id="table" style="font-size: x-small">Population by country</caption>
<thead><tr><th>Country</th><th>World share</th></tr></thead>
<tbody><tr><td>China</td><td>18.47%</td></tr></tbody>
<tbody><tr><td>India</td><td>17.70%</td></tr></tbody>
<tbody><tr><td>United States</td><td>4.25%</td></tr></tbody>
</table>
</body>
</html>