API reference
All classes are under the MejiroEPUB\ namespace. Value objects are
final readonly and validate themselves on construction.
Document
new Document(
DocumentInfo $info,
WritingMode $writingMode = WritingMode::HORIZONTAL_TB,
ReadingDirection $direction = ReadingDirection::AUTO,
?Notation $notation = null, // null = Notation::plain()
StyleOptions $style = new StyleOptions(),
FootnoteStyle $footnoteStyle = new FootnoteStyle(),
?Psr\Log\LoggerInterface $logger = null, // null = log nothing
?DateTimeImmutable $modified = null, // null = now
mixed $sink = null, // a writable stream, or null for an internal buffer
)
| Method | Returns | |
|---|---|---|
cover(string $path, string $alt = '') | Image | Write the cover image and cover page. Before the first section. |
image(string $path, string $alt = '') | Image | Write an image now; place it by putting the Image in a body. |
section(string $title, string|iterable $body) | $this | Write one section. Body items: strings, Paragraph, Image. |
finalize() | void | Write the contents and package documents and close the archive. Idempotent. |
save(string $path) | void | Finalize and copy to a file. Not with a sink. |
output() | string | Finalize and return the bytes. Not with a sink. |
identifier() | string | The identifier in use — yours, or the generated one. |
DocumentInfo
new DocumentInfo(
string $title, // required, not blank
string $language, // required, BCP 47: "ja", "en-US"
?string $author = null,
?string $identifier = null, // null = a random urn:uuid (logged)
?string $publisher = null,
?string $description = null,
?string $source = null,
?DateTimeImmutable $published = null,
)
Optional strings must be null or non-blank. See Metadata.
Enums
| Enum | Cases |
|---|---|
Text\WritingMode | HORIZONTAL_TB (default), VERTICAL_RL |
ReadingDirection | AUTO (follows the writing mode), LEFT_TO_RIGHT, RIGHT_TO_LEFT |
Style\LatinInVertical | MIXED (default), UPRIGHT |
Text\FootnoteNumbering | CONTINUOUS (default), PER_SECTION |
Text\Notation
| Factory | Reads |
|---|---|
Notation::novel(bool $implicitRuby = true) | Web-novel ruby and emphasis dots |
Notation::mejiro() | MejiroPDF's inline syntax, footnotes included |
Notation::plain() | Nothing |
parse(string $line) returns the line as a list of inline nodes, if you want to
see how a line will be read. See Notation.
Text\Paragraph
A paragraph built from parts; parts are never read as notation.
| Method | |
|---|---|
Paragraph::of() | Start an empty paragraph. |
Paragraph::blank() | A blank paragraph. |
->text(string) | Plain text. |
->ruby(string $base, string $reading) | Ruby. |
->emphasis(string) | Emphasis dots. |
->tcy(string) | Tate-chu-yoko. |
->footnote(string $note) | A footnote at this point. Empty is ME-VAL-1001. |
Each method returns a new Paragraph; the original is unchanged.
Style\StyleOptions
new StyleOptions(
bool $autoTcy = true, // two half-width digits upright in vertical text
LatinInVertical $latinInVertical = LatinInVertical::MIXED,
?float $lineHeight = null, // 1.0–3.0; null leaves it to the reader
)
Text\FootnoteStyle
new FootnoteStyle(FootnoteNumbering $numbering = FootnoteNumbering::CONTINUOUS)
Version
Version::VERSION | "0.1.1" |
Version::MAJOR, MINOR, PATCH | integers |
Version::generator() | "MejiroEPUB 0.1.1", as written into every EPUB |
Exceptions
Every library exception implements Exception\MejiroEPUBException and carries a
stable code and a context array:
try {
$book->image($path);
} catch (MejiroEPUB\Exception\MejiroEPUBException $e) {
$e->getErrorCode(); // "ME-IMG-5002"
$e->getContext(); // ['path' => …, …]
}
See Error codes. Misuse of the API — a cover after a
section, an Image from another Document, save() with a sink — throws a
plain LogicException instead: it is a bug to fix, not a condition to handle.