Skip to content

Commit 5dcb8d2

Browse files
Pdf export description inline (#1736)
* Make the markup in table, when it fit to column * Re add maxCharInCell function * more Footnote description inline
1 parent 55aa33a commit 5dcb8d2

File tree

4 files changed

+93
-35
lines changed

4 files changed

+93
-35
lines changed

java/bundles/org.eclipse.set.feature.export/src/org/eclipse/set/feature/export/pdf/TableToTableDocument.xtend

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ class TableToTableDocument {
6262
var String tablename
6363
var int groupNumber
6464
var TableSpanUtils spanUtils
65-
66-
static val String FOOTNOTE_SEPARATOR = ", "
65+
var remarkTextInlnie = true
6766

6867
private new() throws ParserConfigurationException {
6968
val docFactory = DocumentBuilderFactory.newInstance
@@ -116,8 +115,11 @@ class TableToTableDocument {
116115

117116
private def Element create doc.createElement("Table") transform(Table table,
118117
Titlebox titlebox, FreeFieldInfo freeFieldInfo) {
118+
remarkTextInlnie = table.isInlineFootnote
119119
appendChild(table.tablecontent.transform)
120-
appendChild(transformToFootnotes(table))
120+
if (!remarkTextInlnie) {
121+
appendChild(transformToFootnotes(table))
122+
}
121123
appendChild(titlebox.transform)
122124
appendChild(freeFieldInfo.transform)
123125
return
@@ -287,9 +289,7 @@ class TableToTableDocument {
287289
val stringValue = content.plainStringValue
288290
if (isRemarkColumn) {
289291
val child = doc.createElement("UnchangedValue")
290-
element.appendChild(
291-
stringValue.addContentToElement(child, columnNumber,
292-
isRemarkColumn))
292+
stringValue.addContentToElement(child, columnNumber, isRemarkColumn)
293293
element.addFootnoteContent(fc, columnNumber, isRemarkColumn)
294294
} else {
295295
element.textContent = stringValue.checkForTestOutput(columnNumber).
@@ -390,25 +390,26 @@ class TableToTableDocument {
390390

391391
private dispatch def void addFootnoteContent(Element element,
392392
SimpleFootnoteContainer fc, int columnNumber, boolean isRemarkColumn) {
393-
394-
val footnotes = fc.footnotes.map[getFootnoteInfo(fc, it).toShorthand].
395-
iterableToString(FOOTNOTE_SEPARATOR)
393+
val footNotesInfo = fc.footnotes.map[getFootnoteInfo(fc, it)].filterNull
394+
val footnotes = footNotesInfo.map [
395+
remarkTextInlnie ? toText : toShorthand
396+
].iterableToString(FOOTNOTE_SEPARATOR)
396397
element.addFootnoteChild(footnotes, WARNING_MARK_BLACK, columnNumber,
397398
isRemarkColumn)
398399
}
399400

400401
private dispatch def void addFootnoteContent(Element element,
401402
CompareFootnoteContainer fc, int columnNumber, boolean isRemarkColumn) {
402-
403-
val oldFootnotes = fc.oldFootnotes.map [
404-
getFootnoteInfo(fc, it).toShorthand
403+
val oldFootnotes = fc.oldFootnotes.map[getFootnoteInfo(fc, it)].map [
404+
remarkTextInlnie ? toText : toShorthand
405405
].iterableToString(FOOTNOTE_SEPARATOR)
406-
val newFootnotes = fc.newFootnotes.map [
407-
getFootnoteInfo(fc, it).toShorthand
406+
val newFootnotes = fc.newFootnotes.map[getFootnoteInfo(fc, it)].map [
407+
remarkTextInlnie ? toText : toShorthand
408408
].iterableToString(FOOTNOTE_SEPARATOR)
409409
val unchangedFootnotes = fc.unchangedFootnotes.map [
410-
getFootnoteInfo(fc, it).toShorthand
411-
].iterableToString(FOOTNOTE_SEPARATOR)
410+
getFootnoteInfo(fc, it)
411+
].map[remarkTextInlnie ? toText : toShorthand].iterableToString(
412+
FOOTNOTE_SEPARATOR)
412413

413414
element.addFootnoteChild(oldFootnotes, WARNING_MARK_YELLOW,
414415
columnNumber, isRemarkColumn)

java/bundles/org.eclipse.set.feature.table/src/org/eclipse/set/feature/table/ToolboxTableView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ private void updateFootnotes() {
371371
final List<String> lines = new ArrayList<>();
372372
final List<StyleRange> styles = new ArrayList<>();
373373
int startOffset = 0;
374-
375374
for (final FootnoteInfo footnote : TableExtensions
376375
.getAllFootnotes(table)) {
377376
final String text = footnote.toReferenceText();

java/bundles/org.eclipse.set.model.tablemodel.extensions/src/org/eclipse/set/model/tablemodel/extensions/TableExtensions.xtend

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import org.eclipse.set.model.planpro.Basisobjekte.Bearbeitungsvermerk
4141
* Extensions for {@link Table}.
4242
*/
4343
class TableExtensions {
44-
44+
public static val String FOOTNOTE_SEPARATOR = "; "
4545
/**
4646
* @param columnLabels the column labels
4747
*
@@ -454,8 +454,61 @@ class TableExtensions {
454454
}
455455
return getFootnoteInfo(object as Table, fn)
456456
}
457-
457+
458458
static def boolean isTableEmpty(Table table) {
459459
return table.tableRows.nullOrEmpty
460460
}
461+
462+
static def boolean isInlineFootnote(Table table) {
463+
val remarkColumn = table.columndescriptors.findFirst [
464+
isFootnoteReferenceColumn
465+
]
466+
if (remarkColumn === null) {
467+
return false
468+
}
469+
val remarkColumnWidth = remarkColumn.columnWidth
470+
val maxCharInCell = remarkColumnWidth.maxCharInCell
471+
return table.tableRows.forall [ row |
472+
val fc = row.footnotes
473+
if (fc === null) {
474+
return true
475+
}
476+
477+
if (fc instanceof SimpleFootnoteContainer) {
478+
val remarks = fc.footnotes.map[getFootnoteInfo(table, it)].
479+
filterNull
480+
481+
return remarks.isEmpty ||
482+
remarks.map[toText].join(", ").length < maxCharInCell
483+
}
484+
485+
if (fc instanceof CompareFootnoteContainer) {
486+
val oldFootnotes = fc.oldFootnotes.map [
487+
getFootnoteInfo(table, it)
488+
].filterNull
489+
val newFootnotes = fc.newFootnotes.map [
490+
getFootnoteInfo(table, it)
491+
].filterNull
492+
val unchangedFootnotes = fc.unchangedFootnotes.map [
493+
getFootnoteInfo(table, it)
494+
].filterNull
495+
val notEmptyContainer = #[oldFootnotes, newFootnotes,
496+
unchangedFootnotes].filter[!isEmpty]
497+
498+
return switch (notEmptyContainer.size) {
499+
case 0:
500+
true
501+
case 1: {
502+
val remarks = notEmptyContainer.firstOrNull.map[toText].
503+
filterNull
504+
return remarks.isEmpty ||
505+
remarks.join(FOOTNOTE_SEPARATOR).length < maxCharInCell
506+
}
507+
default:
508+
false
509+
}
510+
}
511+
return true
512+
]
513+
}
461514
}

java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/StringExtensions.xtend

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright (c) 2017 DB Netz AG and others.
3-
*
3+
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v2.0
66
* which accompanies this distribution, and is available at
@@ -16,14 +16,15 @@ import java.util.regex.Pattern
1616
* @author Schaefer
1717
*/
1818
class StringExtensions {
19-
20-
static val ENV_PATTERN = Pattern.compile("(?<start>[^$]*)\\$(?<var>[^$]+)\\$(?<end>.*)")
19+
20+
static val ENV_PATTERN = Pattern.compile(
21+
"(?<start>[^$]*)\\$(?<var>[^$]+)\\$(?<end>.*)")
2122
static val ENV_VAR = "var"
22-
23-
23+
2424
/**
2525
* This constant determine manual with OpenSans font
2626
*/
27+
static val int CHARACTER_PRO_CM = 8
2728
static final String ZERO_WIDTH_SPACE = "\u200b"
2829

2930
/**
@@ -45,7 +46,11 @@ class StringExtensions {
4546
static def String intersperseWithZeroSpacesSC(String string) {
4647
return string.replaceAll("([ /\\-_)}\\]])", "$1" + ZERO_WIDTH_SPACE)
4748
}
48-
49+
50+
static def int maxCharInCell(float cellWidth) {
51+
return Math.round(cellWidth * CHARACTER_PRO_CM)
52+
}
53+
4954
/**
5055
* @param string this string
5156
*
@@ -70,25 +75,27 @@ class StringExtensions {
7075
}
7176
return ""
7277
}
73-
78+
7479
/**
7580
* Remove the given suffix from this string.
7681
*
7782
* @param string this string
7883
* @param suffix the given suffix collection
7984
*/
8085
static def String removeSuffix(String string, String... suffix) {
81-
val sortedSuffix = suffix.sortWith([a,b|Integer.compare(b.length, a.length)])
82-
86+
val sortedSuffix = suffix.sortWith([ a, b |
87+
Integer.compare(b.length, a.length)
88+
])
89+
8390
for (p : sortedSuffix) {
8491
if (string.endsWith(p)) {
8592
return string.substring(0, string.length - p.length)
8693
}
8794
}
88-
95+
8996
return string
9097
}
91-
98+
9299
/**
93100
* Compares the arguments. Any argument may be <code>null</code>.
94101
*
@@ -101,7 +108,7 @@ class StringExtensions {
101108
}
102109
return string.equals(other)
103110
}
104-
111+
105112
/**
106113
* Expand the given path with environment variables, marked with dollarsigns.
107114
* <p>
@@ -113,10 +120,8 @@ class StringExtensions {
113120
*/
114121
static def String expandFromEnvironment(String string) {
115122
var String result = String.valueOf(string)
116-
for (var matcher = ENV_PATTERN.matcher(result);
117-
matcher.matches;
118-
matcher = ENV_PATTERN.matcher(result)
119-
) {
123+
for (var matcher = ENV_PATTERN.matcher(result); matcher.
124+
matches; matcher = ENV_PATTERN.matcher(result)) {
120125
val name = matcher.group(ENV_VAR)
121126
val expanded = System.getenv(name)
122127
result = string.replace('''$«name»$''', expanded)

0 commit comments

Comments
 (0)