From 8be6790c362663973cb01e746064d47f082a654c Mon Sep 17 00:00:00 2001 From: Kevin Hendricks Date: Thu, 30 Nov 2023 11:33:19 -0500 Subject: [PATCH] preserve media overlay active class selectors from being considered unused --- ChangeLog.txt | 3 +++ src/MainUI/MainWindow.cpp | 7 ++++++- src/ResourceObjects/OPFResource.cpp | 26 ++++++++++++++++++++++++++ src/ResourceObjects/OPFResource.h | 7 ++++++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9eebcfa14f..453a4cae12 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,9 +3,12 @@ pre-2.x.x - assign menu accelerators P - &Plugins, and K - Chec&kpoints (thank you BeckyEbook) - add ability to change keyboard focus using keyboard shortcuts or menus to BookBrowser, Preview, CodeView, ClipsWindow, and TableOfContents Windows + - preserve Media Overlay Active Classes when deleting unused classes + Bug Fixes - patch Qt6.5.3 to avoid transient child window resize bug on Windows - fix QuickParser bug when parseing attribute names not properly ignoreing all legal whitespace + - make OPF parsing robust to alternative whitespace usage as well Sigil-2.0.2 diff --git a/src/MainUI/MainWindow.cpp b/src/MainUI/MainWindow.cpp index c957fa222a..c8830a6324 100644 --- a/src/MainUI/MainWindow.cpp +++ b/src/MainUI/MainWindow.cpp @@ -2980,12 +2980,17 @@ bool MainWindow::DeleteUnusedStyles(bool in_automate) return false; } + // get list of any media overlay active class selectors from the opf + QStringList activeclassselectors = m_Book->GetOPF()->GetMediaOverlayActiveClassSelectors(); + // This one handles all selector types QList css_selector_usage = BookReports::GetAllCSSSelectorsUsed(m_Book, true); QList css_selectors_to_delete; foreach(BookReports::StyleData *selector, css_selector_usage) { if (selector->html_filename.isEmpty()) { - css_selectors_to_delete.append(selector); + if (!activeclassselectors.contains(selector->css_selector_text)) { + css_selectors_to_delete.append(selector); + } } } diff --git a/src/ResourceObjects/OPFResource.cpp b/src/ResourceObjects/OPFResource.cpp index 4b7668da88..897a39a0b2 100644 --- a/src/ResourceObjects/OPFResource.cpp +++ b/src/ResourceObjects/OPFResource.cpp @@ -57,6 +57,8 @@ #define QT_ENUM_KEEPEMPTYPARTS QString::KeepEmptyParts #endif +static const QString MEDIA_PLAYBACK_ACTIVE_CLASS = "media:playback-active-class"; +static const QString MEDIA_ACTIVE_CLASS = "media:active-class"; static const QString SIGIL_VERSION_META_NAME = "Sigil version"; static const QString OPF_XML_NAMESPACE = "http://www.idpf.org/2007/opf"; static const QString FALLBACK_MIMETYPE = "text/plain"; @@ -561,6 +563,30 @@ QStringList OPFResource::GetSpineOrderBookPaths() const return book_paths_in_reading_order; } + +QStringList OPFResource::GetMediaOverlayActiveClassSelectors() const +{ + QReadLocker locker(&GetLock()); + QStringList activeclassselectors; + QString source = CleanSource::ProcessXML(GetText(),"application/oebps-package+xml"); + OPFParser p; + p.parse(source); + for (int i=0; i < p.m_metadata.count(); ++i) { + if (p.m_metadata.at(i).m_name == "meta") { + MetaEntry me = p.m_metadata.at(i); + QString propval = me.m_atts.value("property", ""); + if (propval == MEDIA_ACTIVE_CLASS) { + activeclassselectors << "." + me.m_content; + } + if (propval == MEDIA_PLAYBACK_ACTIVE_CLASS) { + activeclassselectors << "." + me.m_content; + } + } + } + return activeclassselectors; +} + + QString OPFResource::GetPrimaryBookTitle() const { QString title = ""; diff --git a/src/ResourceObjects/OPFResource.h b/src/ResourceObjects/OPFResource.h index 6cd8bf403b..75743fccb0 100644 --- a/src/ResourceObjects/OPFResource.h +++ b/src/ResourceObjects/OPFResource.h @@ -1,6 +1,6 @@ /************************************************************************ ** -** Copyright (C) 2015-2020 Kevin B. Hendricks, Stratford ON +** Copyright (C) 2015-2023 Kevin B. Hendricks, Stratford ON ** Copyright (C) 2013 John Schember ** Copyright (C) 2009-2011 Strahinja Markovic ** @@ -130,6 +130,11 @@ class OPFResource : public XMLResource */ QList GetDCMetadata() const; + /** + * Returns list of any Media Overlay Active Class Selctors if defined in OPF metadata + */ + QStringList GetMediaOverlayActiveClassSelectors() const; + /** * Returns the values for a specific dc: metadata name. *