Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add binie.md #4

Merged
merged 5 commits into from Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -14,6 +14,10 @@ This project includes two main components:
* [GDI](https://en.wikipedia.org/wiki/Graphics_Device_Interface) printing (Windows) via [Colony NPAPI (npcolony)](https://github.com/hivesolutions/colony-npapi)
* [CUPS](https://en.wikipedia.org/wiki/CUPS) printing (Linux) via [Colony NPAPI (npcolony)](https://github.com/hivesolutions/colony-npapi)

## Binie Specification

For a detailed understanding of the Binie file format used in this project, refer to the [Binie File Format Specification](binie.md). This document outlines the structure and organization of the Binie file format, which is essential for developing compatible applications and tools.

## Installation

### Pre-requisites
Expand Down
84 changes: 84 additions & 0 deletions binie.md
@@ -0,0 +1,84 @@
# Binie File Format Specification 1.0

## Motivation

Binie is a binary file format specification crafted to enable consistent and structured representation of documents, particularly for print media.
It is engineered to support diverse document layouts, allowing various applications to create and interpret Binie-compliant documents reliably. Binie achieves this by defining a clear, extensible structure for document components, including text and images.
This approach ensures that a single document file can be used across different platforms and applications, maintaining its layout integrity and visual fidelity.

## Specification

The Binie file consists of a document header followed by a series of elements. Each element can be either text or an image, each with its specific header and data.

Every integer in the Binie specification is encoded in Little Endian format.

### Binie Header

Binie documents begin with a standard header that includes essential metadata about the document:

| Offset (bytes) | Length (bytes) | Content |
|----------------|----------------|-------------------------|
| 0 | 256 | Document Title |
| 256 | 4 | Document width |
| 260 | 4 | Document height |
| 264 | 4 | Element count |

### Element Header

Following the header, Binie documents contain a series of elements, each with a defined structure.
Each element in the document (text or image) starts with a standard header.

| Offset (from element start) | Length (bytes) | Content |
|-----------------------------|----------------|--------------------|
| 0 | 4 | Element type |
| 4 | 4 | Element data length|

### Text Element

Text elements have their specific header followed by the actual text.
The element type for text elements is identified by the value `1`.

#### Text Element Header

| Offset (from text element start) | Length (bytes) | Content |
|----------------------------------|----------------|---------------------|
| 0 | 8 | Common header |
| 8 | 8 | Position |
| 16 | 256 | Font |
| ... | ... | Additional settings |

#### Text Data

Follows immediately after the text element header.

### Image Element

Image elements contain image data.
The element type for image elements is identified by the value `2`.

#### Image Element Header

| Offset (from image element start) | Length (bytes) | Content |
|-----------------------------------|----------------|--------------------|
| 0 | 8 | Common header |
| 8 | 8 | Position |
| ... | ... | Additional settings|

#### Image Data

Follows immediately after the image element header.

### Text Alignment
hugo-gomes marked this conversation as resolved.
Show resolved Hide resolved

Text alignment within the elements is specified using alignment values. These are:
* `1` for Left alignment
* `2` for Right alignment
* `3` for Center alignment

## Validation and Compatibility

The Binie file format is designed to be robust and flexible. Implementations should handle unexpected values gracefully, defaulting to sensible behavior where possible. For example, unknown element types should be ignored, and missing data should be handled without causing crashes or major issues.

## Future Extensions

The structure of the Binie file format allows for future extensions, such as new element types or additional metadata in headers. Implementations should be designed to accommodate such changes, ensuring backward and forward compatibility.