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

EPUB: add identifiers to doc props #560

Merged
merged 4 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions crengine/include/lvdocview.h
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,8 @@ class LVDocView : public CacheLoadingCallback
lString32 getDescription() { return m_doc_props->getStringDef(DOC_PROP_DESCRIPTION); }
/// returns book keywords (separated by "; ")
lString32 getKeywords() { return m_doc_props->getStringDef(DOC_PROP_KEYWORDS); }
/// returns book identifiers (scheme:identifier separated by ";")
lString32 getIdentifiers() { return m_doc_props->getStringDef(DOC_PROP_IDENTIFIERS); }
baswag marked this conversation as resolved.
Show resolved Hide resolved
/// returns book series name and number (series name #1)
lString32 getSeries()
{
Expand Down
1 change: 1 addition & 0 deletions crengine/include/lvtinydom.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ extern const int gDOMVersionCurrent;
#define DOC_PROP_FILE_CRC32 "doc.file.crc32"
#define DOC_PROP_CODE_BASE "doc.file.code.base"
#define DOC_PROP_COVER_FILE "doc.cover.file"
#define DOC_PROP_IDENTIFIERS "doc.identifiers"
baswag marked this conversation as resolved.
Show resolved Hide resolved

#define DEF_SPACE_WIDTH_SCALE_PERCENT 100
#define DEF_MIN_SPACE_CONDENSING_PERCENT 50
Expand Down
29 changes: 29 additions & 0 deletions crengine/src/epubfmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,35 @@ bool ImportEpubDocument( LVStreamRef stream, ldomDocument * m_doc, LVDocViewCall
m_doc_props->setString(DOC_PROP_KEYWORDS, subjects);
CRLog::info("Authors: %s Title: %s", LCSTR(authors), LCSTR(title));

// Return possibly multiple <dc:identifier> (identifiers)
// as a single doc_props string with values in a key-value format (scheme:identifier) separated by ;
bool identifiers_set = false;
lString32 identifiers;
// Iterate all package/metadata/identifier
lUInt16 identifier_id = doc->getElementNameIndex(U"identifier");
for (size_t i=0; i<nb_metadata_items; i++) {
ldomNode * item = metadata->getChildNode(i);
if ( item->getNodeId() != identifier_id )
continue;
lString32 scheme = item->getAttributeValue(U"scheme");
lString32 identifier;
// In version 3, scheme is not set but the type is rather included in the text itself
if(scheme.empty()) {
identifier = item->getText().trim().lowercase();
}else {
baswag marked this conversation as resolved.
Show resolved Hide resolved
// In version 2, the scheme is only found as attribute
identifier << scheme << ":" << item->getText().trim().lowercase();
baswag marked this conversation as resolved.
Show resolved Hide resolved
}
if (identifiers_set) {
identifiers << ";" << identifier;
}
else {
identifiers << identifier;
identifiers_set = true;
}
}
m_doc_props->setString(DOC_PROP_IDENTIFIERS, identifiers);

bool hasSeriesMeta = false;
bool hasSeriesIdMeta = false;
// Iterate all package/metadata/meta
Expand Down