Files
pdf-odin/pdf.odin
T

47 lines
751 B
Odin
Raw Normal View History

2026-10-11 16:33:19 +02:00
package pdf
import "core:os"
2026-10-11 23:01:37 +02:00
import "core:fmt"
PDF_MAGIC :: "%PDF-"
2026-10-11 16:33:19 +02:00
Error :: enum {
2026-10-11 23:01:37 +02:00
Ok,
2026-10-11 16:33:19 +02:00
File_Read_Error,
2026-10-11 23:01:37 +02:00
InvalidFile,
2026-10-11 16:33:19 +02:00
}
Document :: struct {
2026-10-11 23:01:37 +02:00
version: string
2026-10-11 16:33:19 +02:00
}
open :: proc{
open_file,
open_bytes,
}
2026-10-11 23:01:37 +02:00
open_file :: proc(path: string) -> (doc: ^Document, err: Error) {
2026-10-11 16:33:19 +02:00
data, read_err := os.read_entire_file(path, context.allocator)
if read_err != nil {
return nil, .File_Read_Error
}
return open_bytes(data)
}
2026-10-11 23:01:37 +02:00
open_bytes :: proc(data: []u8) -> (doc: ^Document, err: Error) {
doc = new(Document)
if string(data[:5]) != PDF_MAGIC {
return nil, .InvalidFile
}
doc.version = string(data[5:5+3])
return doc, nil
}
destroy_document :: proc(pdf: ^Document) {
free(pdf)
2026-10-11 16:33:19 +02:00
}