-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
2,736 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ pdf2printable_mad | |
hexdump | ||
baselinify | ||
baselinify_mad | ||
ippposter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef ERROR_H | ||
#define ERROR_H | ||
|
||
#include <optional> | ||
|
||
typedef std::optional<std::string> Error; | ||
|
||
#endif // ERROR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef FUNCTIONS_H | ||
#define FUNCTIONS_H | ||
|
||
#include <functional> | ||
|
||
typedef std::function<bool(unsigned char const*, unsigned int)> WriteFun; | ||
typedef std::function<void(size_t page, size_t total)> ProgressFun; | ||
|
||
#endif // FUNCTIONS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#include "ippattr.h" | ||
#include <iomanip> | ||
|
||
bool IppAttr::isList() const | ||
{ | ||
return is<IppOneSetOf>(); | ||
} | ||
IppOneSetOf IppAttr::asList() const | ||
{ | ||
if(isList()) | ||
{ | ||
return get<IppOneSetOf>(); | ||
} | ||
else | ||
{ | ||
return IppOneSetOf {{value()}}; | ||
} | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, const IppIntRange& ir) | ||
{ | ||
os << "{\"min\": " << ir.low << ", \"max\": " << ir.high << "}"; | ||
return os; | ||
} | ||
std::ostream& operator<<(std::ostream& os, const IppResolution& res) | ||
{ | ||
os << "{\"x\": " << res.x | ||
<< ", \"y\": " << res.y | ||
<< ", \"units\": " << +res.units << "}"; | ||
return os; | ||
} | ||
std::ostream& operator<<(std::ostream& os, const IppDateTime& dt) | ||
{ | ||
// 2000-01-02T00:00:57 GMT+0200 | ||
os << "\"" << std::setfill('0') << std::setw(4) << dt.year << "-" | ||
<< std::setw(2) << +dt.month << "-" << std::setw(2) << +dt.day | ||
<< "T" << std::setw(2) << +dt.hour << ":" | ||
<< std::setw(2) << +dt.minutes << ":" << std::setw(2) << +dt.seconds | ||
<< "." << std::setw(3) << dt.deciSeconds*100 << " GMT" << dt.plusMinus | ||
<< std::setw(2) << +dt.utcHOffset << std::setw(2) << +dt.utcMOffset << "\""; | ||
return os; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, const IppValue& iv) | ||
{ | ||
if(iv.is<std::string>()) | ||
{ | ||
os << "\"" << iv.get<std::string>() << "\""; | ||
} | ||
else if(iv.is<int>()) | ||
{ | ||
os << iv.get<int>(); | ||
} | ||
else if(iv.is<bool>()) | ||
{ | ||
os << iv.get<bool>(); | ||
} | ||
else if(iv.is<IppIntRange>()) | ||
{ | ||
os << iv.get<IppIntRange>(); | ||
} | ||
else if(iv.is<IppResolution>()) | ||
{ | ||
os << iv.get<IppResolution>(); | ||
} | ||
else if(iv.is<IppDateTime>()) | ||
{ | ||
os << iv.get<IppDateTime>(); | ||
} | ||
else if(iv.is<IppOneSetOf>()) | ||
{ | ||
IppOneSetOf oneSet = iv.get<IppOneSetOf>(); | ||
os << "[" << oneSet.takeFront(); | ||
for(IppValue iv2 : oneSet) | ||
{ | ||
os << ", " << iv2; | ||
} | ||
os << "]"; | ||
} | ||
else if(iv.is<IppCollection>()) | ||
{ | ||
os << "{"; | ||
IppCollection ippCollection = iv.get<IppCollection>(); | ||
IppCollection::const_iterator it = ippCollection.cbegin(); | ||
os << "\"" << it->first << "\": " << it->second; | ||
it++; | ||
for(; it != ippCollection.cend(); it++) | ||
{ | ||
os << ", \"" << it->first << "\": " << it->second; | ||
} | ||
os << "}"; | ||
} | ||
else | ||
{ | ||
os << "unhandled value"; | ||
} | ||
|
||
return os; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, const IppAttrs& as) | ||
{ | ||
if(as.empty()) | ||
{ | ||
os << "{}" << std::endl; | ||
return os; | ||
} | ||
|
||
IppAttrs::const_iterator it = as.cbegin(); | ||
os << "{" | ||
<< "\"" << it->first << "\": {\"tag\": " << +it->second.tag() | ||
<< ", \"value\": " << it->second.value() << "}"; | ||
it++; | ||
for(; it != as.cend(); it++) | ||
{ | ||
os << "," << std::endl | ||
<< "\"" << it->first << "\": {\"tag\": " << +it->second.tag() | ||
<< ", \"value\": " << it->second.value() << "}"; | ||
} | ||
os << "}" << std::endl; | ||
return os; | ||
} | ||
|
||
bool IppCollection::has(std::string key) const | ||
{ | ||
return find(key) != end(); | ||
} | ||
|
||
void IppCollection::set(std::string key, IppAttr value) | ||
{ | ||
insert_or_assign(key, value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
#ifndef IPPATTR_H | ||
#define IPPATTR_H | ||
|
||
#include "list.h" | ||
#include <cstdint> | ||
#include <string> | ||
#include <vector> | ||
#include <map> | ||
#include <iostream> | ||
#include "polymorph.h" | ||
|
||
struct IppOneSetOf; | ||
struct IppCollection; | ||
class IppAttr; | ||
|
||
struct IppIntRange | ||
{ | ||
int32_t low = 0; | ||
int32_t high = 0; | ||
|
||
bool operator==(const IppIntRange& other) const | ||
{ | ||
return other.low == low && other.high == high; | ||
} | ||
}; | ||
|
||
struct IppResolution | ||
{ | ||
enum Units : uint8_t | ||
{ | ||
Invalid=0, | ||
DPI=3, | ||
DPCM=4 | ||
}; | ||
|
||
uint32_t x = 0; | ||
uint32_t y = 0; | ||
uint8_t units = Invalid; | ||
|
||
bool operator==(const IppResolution& other) const | ||
{ | ||
return other.units == units && other.x == x && other.y == y; | ||
} | ||
}; | ||
|
||
struct IppDateTime | ||
{ | ||
uint16_t year = 0; | ||
uint8_t month = 0; | ||
uint8_t day = 0; | ||
uint8_t hour = 0; | ||
uint8_t minutes = 0; | ||
uint8_t seconds = 0; | ||
uint8_t deciSeconds = 0; | ||
uint8_t plusMinus = '+'; | ||
uint8_t utcHOffset = 0; | ||
uint8_t utcMOffset = 0; | ||
|
||
bool operator==(const IppDateTime& other) const | ||
{ | ||
return other.year == year && | ||
other.month == month && | ||
other.day == day && | ||
other.hour == hour && | ||
other.minutes == minutes && | ||
other.seconds == seconds && | ||
other.deciSeconds == deciSeconds && | ||
other.plusMinus == plusMinus && | ||
other.utcHOffset == utcHOffset && | ||
other.utcMOffset == utcMOffset; | ||
} | ||
}; | ||
|
||
using IppValue = Polymorph<std::string, int, bool, | ||
IppIntRange, IppResolution, IppDateTime, | ||
IppOneSetOf, IppCollection>; | ||
|
||
struct IppOneSetOf: public List<IppValue> | ||
{ | ||
using List<IppValue>::List; | ||
}; | ||
|
||
struct IppCollection: public std::map<std::string, IppAttr> | ||
{ | ||
using std::map<std::string, IppAttr>::map; | ||
bool has(std::string key) const; | ||
void set(std::string key, IppAttr value); | ||
}; | ||
|
||
class IppAttr : public IppValue | ||
{ | ||
public: | ||
bool isList() const ; | ||
IppOneSetOf asList() const; | ||
|
||
template <typename T> | ||
IppAttr(uint8_t tag, T value) : IppValue(value), _tag(tag) {} | ||
|
||
uint8_t tag() const {return _tag;} | ||
IppValue value() const {return *this;} | ||
|
||
private: | ||
uint8_t _tag; | ||
|
||
}; | ||
|
||
struct IppAttrs: public std::map<std::string, IppAttr> | ||
{ | ||
using std::map<std::string, IppAttr>::map; | ||
|
||
bool has(std::string key) const | ||
{ | ||
return find(key) != end(); | ||
} | ||
|
||
template <typename T> | ||
T get(std::string name, T res=T()) const | ||
{ | ||
if(find(name) != end()) | ||
{ | ||
res = at(name).get<T>(); | ||
} | ||
return res; | ||
} | ||
|
||
void set(std::string key, IppAttr value) | ||
{ | ||
insert_or_assign(key, value); | ||
} | ||
|
||
template <typename T> | ||
List<T> getList(std::string name) const | ||
{ | ||
List<T> res; | ||
if(has(name)) | ||
{ | ||
for(const IppValue& v : at(name).asList()) | ||
{ | ||
res.push_back(v.get<T>()); | ||
} | ||
} | ||
return res; | ||
} | ||
}; | ||
|
||
std::ostream& operator<<(std::ostream& os, const IppIntRange& iv); | ||
std::ostream& operator<<(std::ostream& os, const IppResolution& iv); | ||
std::ostream& operator<<(std::ostream& os, const IppDateTime& iv); | ||
std::ostream& operator<<(std::ostream& os, const IppValue& iv); | ||
|
||
std::ostream& operator<<(std::ostream& os, const IppAttrs& as); | ||
|
||
#endif // IPPATTR_H |
Oops, something went wrong.