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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ The text of a sheet prints too: a text note's RTF string (class 0x0F83 block) is
- API: `RvtIO.Pdf.PdfDocument` writes PDF 1.4 without a third-party library: pages of A4 to A0 or any size in millimetres, vector lines, polylines and rectangles with millimetre line widths, and single-line text in the standard Helvetica font (printable ASCII only; an embedded font for Cyrillic comes with the sheet renderer). `PdfPage.DrawLine`, `DrawPolyline`, `DrawRectangle` and `DrawText` work in millimetres from the lower-left corner, y up, the frame a printed sheet uses. This is the output layer of the sheet printing work (#18); no reader data is rendered into a page yet. Measured: a page of the decoded title block linework of one sheet is written as an A2 landscape PDF; the 10 tests parse the document back from its bytes and check the operators, the page boxes and the cross-reference offsets. No existing output changes.

- API and CLI: `RvtIO.Sheets.SheetCatalog` lists the sheets of a file and the viewports placed on them, and reports what the release does not decode. A sheet is an element that carries the `Sheet Number` or `Sheet Name` parameter (class 995 of the Revit 2022 schema); the `OST_Sheets` category is not used, because every block whose class word is 0x03E3 takes it and one architectural sample has 14,354 elements of that category against 100 sheets. A `SheetRecord` carries the number, name, issue date, the drawn/designed/checked/approved by-lines, the view scale, the viewports of the sheet and the elements the sheet owns; a `ViewportRecord` carries its sheet and detail number. Ownership comes from the stored `m_ownerDBViewId`, now exposed as `Element.OwnerViewId` (null when no view owns the element). `SheetCatalog.Issues` names the missing pieces instead of hiding them: page size (kept in the title block family), view placement (the viewport block stores only the view title label origin), the displayed view (reached through the viewer element, schema class 621, which is not decoded), 2D content and the crop region. `rvtio sheets <file.rvt> [output.json]` writes the same catalog as JSON (exit code 0 written, 1 usage or an unwritable output path, 2 an unreadable file). The catalog exposes no coordinate, size or unit, because no sheet coordinate is decoded yet. Measured on one architectural sample of Revit 2022: 100 sheets, 97 viewports placed on sheets, 97 sheets with owned elements (12 to 143 each); on a second sample 17 sheets and 17 viewports, every sheet without a number. In a Revit 2024 and a Revit 2025 save of the same project the catalog is empty: the reader reads those files by their own class schema, maps neither the sheet class nor any viewport reference, and the tool reports the empty result on standard error; covering those view classes is future work. The full JSON and the compact JSON of the sample are byte-for-byte identical to the build before this entry (the public property is not serialized), and the 16 new library tests (one of them on a private project fixture, skipped without it) and 3 new CLI tests pass.
- Printing: the embedded title font prefers Arial's metric-compatible substitutes (Liberation Sans, Arimo) over DejaVu Sans on Linux, so a title wraps the same on every machine, and `RVTIO_FONTS` names extra folders of font files searched first (`:` on Linux/macOS, `;` on Windows), as in rvt-prt's `RVT_PRT_FONTS`. New tests: `PdfFontsTests`.

- Tests: adds `IndependentInflaterCrossCheckTests` to cross-check every compressed `Formats/*`, `Global/*` and `Partitions/*` stream and gzip member (checked-in fixtures and synthetic multi-page `.rvt` containers in CI, plus public `.rvt` and `.rfa` samples when `RVTIO_TEST_FILES` is set) against `System.IO.Compression.DeflateStream`, asserting equal byte length, SHA-256 digest, CRC-32, gzip `ISIZE` trailer and format-9 segment `unc` and record counts while failing strictly on integrity mismatches independently of dictionary-chained or Deflate64 skip classification and reporting compared and skipped counts with reasons. (Closes #95)
- Adds `--ifc-length-unit <mm|m|ft>` (`IfcExporter.LengthUnit` in the library) to override the length unit family declared in the IFC file (`Millimetre`, `Metre` or `Foot`), scale all coordinates, areas, volumes and base quantities consistently, and name `.SQUARE_METRE.` and `.CUBIC_METRE.` on the SI base units referenced by `Foot` area and volume conversion units across both profiles; omitting the setting keeps the project's stored length unit (or millimetres in the legacy profile) byte-for-byte unchanged, and unsupported unit names exit with code 1. Compact JSON keeps the project's formatted display units and full JSON keeps Revit's internal units. (Refs #51)
- Export report and diagnostics: `streams[].unpackedBytes` (`StreamRecord.UnpackedBytes`) records the inflated byte size of every decoded stream alongside `rawBytes`, and `export.geometry` (`exact`, `approximated`, `boxOnly`, `none`) and `export.elements[]` (`GeometryQualityClass`, `ElementGeometryQuality`, `IfcExporter.ExportedElementQualities`) report the geometry quality class of each exported element in IFC, compact JSON and full JSON exports with totals that sum to `export.exported`. (Closes #96)
Expand Down
5 changes: 3 additions & 2 deletions docs/printing.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ stays empty.
| Room legend | below the plan: a colour swatch and the name of every kind of room on it |

The page is white with a frame at the margin, and the drawing is centred. The title (the level name and the scale) is
written with an embedded TrueType font found on the machine (Arial, Segoe UI or Tahoma on Windows, DejaVu Sans on Linux,
Arial or Helvetica Neue on macOS); without such a font the page is drawn without a title, because the standard PDF font
written with an embedded TrueType font found on the machine (Arial or its metric-compatible substitutes
Liberation Sans and Arimo on Linux, Arial on macOS, Arial, Segoe UI or Tahoma on Windows; `RVTIO_FONTS` names extra
folders searched first, `:` on Linux/macOS and `;` on Windows, as in rvt-prt's `RVT_PRT_FONTS`); without such a font the page is drawn without a title, because the standard PDF font
holds no Cyrillic. Elements are selected by their level
(`LEVEL_PARAM`); a wall without a location line or a column without a footprint is left out and counted by neither
selection nor drawing.
Expand Down
2 changes: 1 addition & 1 deletion docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ See [printing a plan](printing.md) for what is drawn, what is not, and the roadm
| `PdfPageSize` | Paper sizes A4 to A0 in millimetres, `Landscape` for the turned page. |
| `PdfTextAlignment` | `Left`, `Center`, `Right`: where the text anchor sits. |
| `PdfTrueTypeFont` | A TrueType font parsed for embedding (`UnitsPerEm`, `GlyphOf`, `AdvanceOf`), drawn as a Type0 font with Identity-H encoding and a ToUnicode map, so text in the scripts it covers (Cyrillic included) is real, selectable PDF text. |
| `PdfFonts` | `TryFind` loads the first TrueType font found on the machine (Arial, Segoe UI, Tahoma, DejaVu Sans, Helvetica Neue). |
| `PdfFonts` | `TryFind` loads the first TrueType font found on the machine (Arial, its metric-compatible substitutes Liberation Sans and Arimo, Segoe UI, Tahoma, DejaVu Sans, Helvetica Neue); `RVTIO_FONTS` names extra folders searched first. |

Without `PdfDocument.Font` the writer uses the standard Helvetica font, which holds printable ASCII only, and a text with
another character is refused. With it, every text is written with the embedded font.
Expand Down
71 changes: 64 additions & 7 deletions src/RvtIO/Pdf/PdfFonts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,34 @@ namespace RvtIO.Pdf;
/// <summary>Where the print pipeline finds a TrueType font to embed.</summary>
public static class PdfFonts
{
/// <summary>The font files tried in order: Arial, Segoe UI and Tahoma on Windows, DejaVu Sans on Linux, Arial and
/// Helvetica Neue on macOS.</summary>
/// <summary>Environment variable with extra folders of font files, searched first.
/// Several folders are separated by <c>:</c> on Linux/macOS and <c>;</c> on Windows,
/// as in rvt-prt's <c>RVT_PRT_FONTS</c>.</summary>
public const string FontsEnvVar = "RVTIO_FONTS";

/// <summary>File names tried in each extra folder first: Arial and its metric-compatible
/// substitutes (Liberation Sans, Arimo), which wrap and fit text as Arial does.</summary>
private static readonly string[] ExtraFileNames =
[
"arial.ttf",
"Arial.ttf",
"LiberationSans-Regular.ttf",
"Arimo-Regular.ttf",
"DejaVuSans.ttf",
];

/// <summary>The font files tried in order: Arial and its metric-compatible substitutes
/// (Liberation Sans, Arimo) on Linux, Arial on macOS and Windows, then Segoe UI and Tahoma
/// on Windows, DejaVu Sans and Helvetica Neue. A substitute keeps the widths of Arial,
/// so a title wraps the same on every machine.</summary>
private static readonly string[] Candidates =
[
// Debian Bookworm and later ship Liberation Sans in fonts-liberation2.
"/usr/share/fonts/truetype/liberation2/LiberationSans-Regular.ttf",
"/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
"/usr/share/fonts/TTF/LiberationSans-Regular.ttf",
"/usr/share/fonts/truetype/arimo/Arimo-Regular.ttf",
"/usr/share/fonts/TTF/Arimo-Regular.ttf",
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
"/usr/share/fonts/TTF/DejaVuSans.ttf",
"/System/Library/Fonts/Supplemental/Arial.ttf",
Expand All @@ -16,13 +40,17 @@ public static class PdfFonts
@"C:\Windows\Fonts\tahoma.ttf",
];

/// <summary>Loads the first font file of <see cref="Candidates"/> that exists and parses.</summary>
/// <summary>Loads the first font file of <see cref="Candidates"/> that exists and parses,
/// after the folders of <see cref="FontsEnvVar"/>.</summary>
/// <param name="path">The file that was used, or null when none exists.</param>
/// <returns>The font, or null when no candidate is a TrueType font this reader supports.</returns>
public static PdfTrueTypeFont? TryFind(out string? path)
public static PdfTrueTypeFont? TryFind(out string? path) =>
TryFind(Environment.GetEnvironmentVariable, out path);

internal static PdfTrueTypeFont? TryFind(Func<string, string?> getEnv, out string? path)
{
path = null;
foreach (string candidate in Candidates)
foreach (string candidate in CandidateFiles(getEnv))
{
if (!File.Exists(candidate)) continue;
try
Expand All @@ -31,11 +59,40 @@ public static class PdfFonts
path = candidate;
return font;
}
catch (Exception exception) when (exception is NotSupportedException or IOException or UnauthorizedAccessException)
catch (Exception exception) when (exception is NotSupportedException or IOException or UnauthorizedAccessException
// A corrupt candidate must not abort the search: every out-of-range table read already
// reports NotSupportedException, this covers any other malformed-input failure.
or ArgumentException)
{
// A .ttc collection or a font without a Unicode cmap: try the next candidate.
// A .ttc collection, a font without a Unicode cmap or a corrupt file: try the next candidate.
}
}
return null;
}

/// <summary>Every font file tried in order, without touching the disk: the files of the
/// <see cref="FontsEnvVar"/> folders first, then <see cref="Candidates"/>.</summary>
internal static IReadOnlyList<string> CandidateFiles(Func<string, string?> getEnv)
{
var files = new List<string>();
string? extra = null;
try
{
extra = getEnv(FontsEnvVar);
}
catch (Exception exception) when (exception is IOException or UnauthorizedAccessException)
{
// No extra folders then; the machine candidates still stand.
}
if (!string.IsNullOrWhiteSpace(extra))
{
foreach (string folder in extra.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
{
foreach (string name in ExtraFileNames)
files.Add(Path.Combine(folder, name));
}
}
files.AddRange(Candidates);
return files;
}
}
Loading
Loading