ged2doc.utils¶
Various utility methods.
Functions
|
Returns encoded person reference. |
|
Returns image MIME type or |
|
Resize image to fit given size. |
|
Save image into output file. |
Returns list of supported languages. |
|
|
Finds primary person image file name. |
|
Resize a box so that it fits into other box and keeps aspect ratio. |
|
Split text with embedded references into a sequence of text and references. |
Try to guess system language. |
-
ged2doc.utils.
resize
(size, max_size, reduce_only=True)[source]¶ Resize a box so that it fits into other box and keeps aspect ratio.
- Parameters
- size
tuple
Box to resize, (width, height). Elements of tuple are either numbers or
ged2doc.size.Size
instances.- max_size
tuple
Box to fit new resized box into, (width, height).
- reduce_only
bool
If True (default) and size is smaller than max_size then return original box.
- size
- Returns
- width, height
Tuple (width, height) representing resized box. Type of the elements is the same as the type of the
size
elements.
-
ged2doc.utils.
person_image_file
(person)[source]¶ Finds primary person image file name.
Scans INDI’s OBJE records and finds “best” FILE record from those.
- Parameters
- person
ged4py.model.Individual
INDI record representation.
- person
- Returns
- file_name
str
orNone
String with file name or
None
.
- file_name
Notes
OBJE record contains one (in 5.5) or few (in 5.5.1) related multimedia files. In 5.5 file contents can be embedded as BLOB record though we do not support this. In 5.5.1 file name is stored in a record.
In 5.5.1 OBJE record is supposed to have structure:
OBJE +1 FILE <MULTIMEDIA_FILE_REFN> {1:M} +2 FORM <MULTIMEDIA_FORMAT> {1:1} +3 MEDI <SOURCE_MEDIA_TYPE> {0:1} +1 TITL <DESCRIPTIVE_TITLE> {0:1} +1 _PRIM {Y|N} {0:1}
Some applications which claim to be 5.5.1 version still store OBJE record in 5.5-like format:
OBJE +1 FILE <MULTIMEDIA_FILE_REFN> {1:1} +1 FORM <MULTIMEDIA_FORMAT> {1:1} +1 TITL <DESCRIPTIVE_TITLE> {0:1} +1 _PRIM {Y|N} {0:1}
This method returns the name of the FILE corresponding to _PRIM=Y, or if there is no _PRIM record then the first FILE record. Potentially we also need to look at MEDI record to only chose image type, but I have not seen examples of MEDI use yet, so for now I only select FORM which correspond to images.
-
ged2doc.utils.
languages
()[source]¶ Returns list of supported languages.
This should correspond to the existing translations and needs to be updated when new translation is added.
- Returns
- languages
list
[str
]
- languages
-
ged2doc.utils.
system_lang
()[source]¶ Try to guess system language.
- Returns
- language
str
Guessed system language, “en” is returned as a fallback.
- language
-
ged2doc.utils.
embed_ref
(xref_id, name)[source]¶ Returns encoded person reference.
Encoded reference consists of ASCII character
SOH
(0x01
) followed by reference ID,STX
(0x02
), person name, andETX
(0x03
).- Parameters
- xref_id
str
Reference ID for a person.
- name
str
Person name.
- xref_id
-
ged2doc.utils.
split_refs
(text)[source]¶ Split text with embedded references into a sequence of text and references.
Reference is returned as tuple (id, name).
- Yields
- item
str
ortuple
Pieces of text and references.
- item
-
ged2doc.utils.
img_mime_type
(img)[source]¶ Returns image MIME type or
None
.- Parameters
- img: `PIL.Image`
PIL Image object.
- Returns
- mime_type
str
MIME string like “image/jpg” or
None
.
- mime_type