Skip to content

Commit

Permalink
move props code to DocProperites.[h|cpp]
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed May 23, 2024
1 parent cc94a78 commit 2ce4000
Show file tree
Hide file tree
Showing 32 changed files with 134 additions and 79 deletions.
10 changes: 7 additions & 3 deletions premake5.files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ function sumatrapdf_files()
"DisplayModel.*",
"DisplayMode.*",
"DocController.h",
"DocProperties.*",
"EditAnnotations.*",
"ExternalViewers.*",
"Favorites.*",
Expand Down Expand Up @@ -788,6 +789,8 @@ end
function engines_files()
files_in_dir("src", {
"Annotation.*",
"ChmFile.*",
"DocProperties.*",
"EngineBase.*",
"EngineCreate.*",
"EngineDjVu.*",
Expand All @@ -798,7 +801,6 @@ function engines_files()
"EngineMupdfImpl.*",
"EnginePs.*",
"EngineAll.h",
"ChmFile.*",
"EbookDoc.*",
"EbookFormatter.*",
"HtmlFormatter.*",
Expand Down Expand Up @@ -1195,6 +1197,7 @@ function pdf_preview_files()
"mui/Mui.*",
"mui/TextRender.*",
"ChmFile.*",
"DocProperties.*",
"EbookDoc.*",
"EbookFormatter.*",
"EngineBase.*",
Expand Down Expand Up @@ -1225,14 +1228,15 @@ function search_filter_files()
files_in_dir("src", {
"utils/LogDbg.*",
"MUPDF_Exports.cpp",
"DocProperties.*",
"EbookDoc.*",
"EngineBase.*",
"EngineAll.h",
"EngineMupdf.*",
"EngineMupdfImpl.*",
"MobiDoc.*",
"PalmDbReader.*",
"RegistrySearchFilter.*",
"MobiDoc.*",
"EbookDoc.*",
})

filter {"configurations:Debug or DebugFull"}
Expand Down
1 change: 1 addition & 0 deletions src/ChmFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "utils/WinUtil.h"

#include "DocController.h"
#include "DocProperties.h"
#include "EbookBase.h"
#include "ChmFile.h"

Expand Down
21 changes: 0 additions & 21 deletions src/DocController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,6 @@ struct MainWindow;
struct FileState;
enum class DisplayMode;

// TODO: those are implementd in EngineBase.cpp
extern const char* kPropTitle;
extern const char* kPropAuthor;
extern const char* kPropCopyright;
extern const char* kPropSubject;
extern const char* kPropCreationDate;
extern const char* kPropModificationDate;
extern const char* kPropCreatorApp;
extern const char* kPropUnsupportedFeatures;
extern const char* kPropFontList;
extern const char* kPropPdfVersion;
extern const char* kPropPdfProducer;
extern const char* kPropPdfFileStructure;

// Props are stored in StrVec as key, value sequentially
using Props = StrVec;
int PropsCount(const Props& props);
int FindPropIdx(const Props& props, const char* key);
char* FindProp(const Props& props, const char* key);
void AddProp(Props& props, const char* key, const char* val, bool replaceIfExists = false);

using onBitmapRenderedCb = std::function<void(RenderedBitmap*)>;

struct ILinkHandler {
Expand Down
61 changes: 61 additions & 0 deletions src/DocProperties.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* Copyright 2022 the SumatraPDF project authors (see AUTHORS file).
License: Simplified BSD (see COPYING.BSD) */

#include "utils/BaseUtil.h"

#include "DocProperties.h"

const char* kPropTitle = "title";
const char* kPropAuthor = "author";
const char* kPropCopyright = "copyright";
const char* kPropSubject = "subject";
const char* kPropCreationDate = "creationDate";
const char* kPropModificationDate = "modDate";
const char* kPropCreatorApp = "creatorApp";
const char* kPropUnsupportedFeatures = "unsupportedFeatures";
const char* kPropFontList = "fontList";
const char* kPropPdfVersion = "pdfVersion";
const char* kPropPdfProducer = "pdfProducer";
const char* kPropPdfFileStructure = "pdfFileStructure";

int PropsCount(const Props& props) {
int n = props.Size();
CrashIf(n < 0 || (n % 2) != 0);
return n / 2;
}

int FindPropIdx(const Props& props, const char* key) {
int n = PropsCount(props);
for (int i = 0; i < n; i++) {
int idx = i * 2;
char* v = props.At(idx);
if (str::Eq(v, key)) {
return idx;
}
}
return -1;
}

char* FindProp(const Props& props, const char* key) {
int idx = FindPropIdx(props, key);
if (idx < 0) {
return nullptr;
}
char* v = props.At(idx);
return v;
}

void AddProp(Props& props, const char* key, const char* val, bool replaceIfExists) {
CrashIf(!key || !val);
int idx = FindPropIdx(props, key);
if (idx < 0) {
// doesn't exsit
props.Append(key);
props.Append(val);
return;
}
if (!replaceIfExists) {
return;
}
props.SetAt(idx + 1, val);
}
22 changes: 22 additions & 0 deletions src/DocProperties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright 2022 the SumatraPDF project authors (see AUTHORS file).
License: Simplified BSD (see COPYING.BSD) */

extern const char* kPropTitle;
extern const char* kPropAuthor;
extern const char* kPropCopyright;
extern const char* kPropSubject;
extern const char* kPropCreationDate;
extern const char* kPropModificationDate;
extern const char* kPropCreatorApp;
extern const char* kPropUnsupportedFeatures;
extern const char* kPropFontList;
extern const char* kPropPdfVersion;
extern const char* kPropPdfProducer;
extern const char* kPropPdfFileStructure;

// Props are stored in StrVec as key, value sequentially
using Props = StrVec;
int PropsCount(const Props& props);
int FindPropIdx(const Props& props, const char* key);
char* FindProp(const Props& props, const char* key);
void AddProp(Props& props, const char* key, const char* val, bool replaceIfExists = false);
1 change: 1 addition & 0 deletions src/EbookDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "wingui/UIModels.h"

#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EbookBase.h"
Expand Down
1 change: 1 addition & 0 deletions src/EbookFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "wingui/UIModels.h"

#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EbookBase.h"
Expand Down
55 changes: 0 additions & 55 deletions src/EngineBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,6 @@

#include "utils/Log.h"

const char* kPropTitle = "title";
const char* kPropAuthor = "author";
const char* kPropCopyright = "copyright";
const char* kPropSubject = "subject";
const char* kPropCreationDate = "creationDate";
const char* kPropModificationDate = "modDate";
const char* kPropCreatorApp = "creatorApp";
const char* kPropUnsupportedFeatures = "unsupportedFeatures";
const char* kPropFontList = "fontList";
const char* kPropPdfVersion = "pdfVersion";
const char* kPropPdfProducer = "pdfProducer";
const char* kPropPdfFileStructure = "pdfFileStructure";

Kind kindPageElementDest = "dest";
Kind kindPageElementImage = "image";
Kind kindPageElementComment = "comment";
Expand All @@ -52,48 +39,6 @@ static Kind destKinds[] = {
};
// clang-format on

int PropsCount(const Props& props) {
int n = props.Size();
CrashIf(n < 0 || (n % 2) != 0);
return n / 2;
}

int FindPropIdx(const Props& props, const char* key) {
int n = PropsCount(props);
for (int i = 0; i < n; i++) {
int idx = i * 2;
char* v = props.At(idx);
if (str::Eq(v, key)) {
return idx;
}
}
return -1;
}

char* FindProp(const Props& props, const char* key) {
int idx = FindPropIdx(props, key);
if (idx < 0) {
return nullptr;
}
char* v = props.At(idx);
return v;
}

void AddProp(Props& props, const char* key, const char* val, bool replaceIfExists) {
CrashIf(!key || !val);
int idx = FindPropIdx(props, key);
if (idx < 0) {
// doesn't exsit
props.Append(key);
props.Append(val);
return;
}
if (!replaceIfExists) {
return;
}
props.SetAt(idx + 1, val);
}

bool IsExternalUrl(const WCHAR* url) {
return str::StartsWithI(url, L"http://") || str::StartsWithI(url, L"https://") || str::StartsWithI(url, L"mailto:");
}
Expand Down
1 change: 1 addition & 0 deletions src/EngineDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "wingui/UIModels.h"

#include "Settings.h"
#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EngineAll.h"
Expand Down
1 change: 1 addition & 0 deletions src/EngineEbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "wingui/UIModels.h"

#include "DocProperties.h"
#include "DocController.h"
#include "FzImgReader.h"
#include "EngineBase.h"
Expand Down
1 change: 1 addition & 0 deletions src/EngineImages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "wingui/UIModels.h"

#include "FzImgReader.h"
#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EngineAll.h"
Expand Down
1 change: 1 addition & 0 deletions src/EngineMupdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern "C" {

#include "AppColors.h"
#include "Annotation.h"
#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EngineMupdf.h"
Expand Down
1 change: 1 addition & 0 deletions src/EnginePs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "wingui/UIModels.h"

#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EngineAll.h"
Expand Down
1 change: 1 addition & 0 deletions src/MobiDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "wingui/UIModels.h"

#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EbookBase.h"
Expand Down
1 change: 1 addition & 0 deletions src/PdfCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern "C" {
#include "wingui/UIModels.h"

#include "Settings.h"
#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "Annotation.h"
Expand Down
1 change: 1 addition & 0 deletions src/Scratch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "wingui/WinGui.h"

#include "Settings.h"
#include "DocProperties.h"
#include "DocController.h"
#include "PalmDbReader.h"
#include "EbookBase.h"
Expand Down
1 change: 1 addition & 0 deletions src/SumatraPDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "Settings.h"
#include "DisplayMode.h"
#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EngineAll.h"
Expand Down
1 change: 1 addition & 0 deletions src/SumatraProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "wingui/WinGui.h"

#include "Settings.h"
#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EngineAll.h"
Expand Down
1 change: 1 addition & 0 deletions src/Tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "wingui/UIModels.h"

#include "Settings.h"
#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EbookBase.h"
Expand Down
1 change: 1 addition & 0 deletions src/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "wingui/UIModels.h"

#include "Settings.h"
#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EngineAll.h"
Expand Down
1 change: 1 addition & 0 deletions src/ifilter/EpubFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "wingui/UIModels.h"

#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EbookBase.h"
Expand Down
1 change: 1 addition & 0 deletions src/ifilter/PdfFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "wingui/UIModels.h"

#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EngineAll.h"
Expand Down
1 change: 1 addition & 0 deletions src/regress/Regress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ To write new regression test:
#include "wingui/UIModels.h"

#include "Settings.h"
#include "DocProperties.h"
#include "DocController.h"
#include "EngineBase.h"
#include "EbookBase.h"
Expand Down
2 changes: 2 additions & 0 deletions vs2022/PdfFilter.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\src\DocProperties.h" />
<ClInclude Include="..\src\EbookDoc.h" />
<ClInclude Include="..\src\EngineAll.h" />
<ClInclude Include="..\src\EngineBase.h" />
Expand All @@ -903,6 +904,7 @@
<ClInclude Include="..\src\ifilter\TeXFilter.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\DocProperties.cpp" />
<ClCompile Include="..\src\EbookDoc.cpp" />
<ClCompile Include="..\src\EngineBase.cpp" />
<ClCompile Include="..\src\EngineMupdf.cpp" />
Expand Down

0 comments on commit 2ce4000

Please sign in to comment.