Skip to content

Commit

Permalink
:) going on porting #303
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercury13 committed Aug 25, 2023
1 parent 98f177d commit dc1bced
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 26 deletions.
2 changes: 2 additions & 0 deletions GlyphWiki2/KageDemo/KageDemo.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ CONFIG(debug, debug|release) {
SOURCES += \
../../Libs/SelfMade/Strings/u_Strings.cpp \
../KageLibs/kage.cpp \
../KageLibs/kageQt.cpp \
main.cpp \
FmMain.cpp

HEADERS += \
../../Libs/SelfMade/Strings/u_Strings.h \
../KageLibs/kage.h \
../KageLibs/kageQt.h \
../KageLibs/u_MaybeInt.h \
FmMain.h

Expand Down
77 changes: 64 additions & 13 deletions GlyphWiki2/KageLibs/kage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,68 @@ namespace {
} // anon namespace


std::string kage::Glyph::toSvg(const GlyphSets& sets) const
///// Glyph ////////////////////////////////////////////////////////////////////


void kage::Glyph::adjustStrokes(const GlyphSets& sets)
{
std::string r;
if (sets.style == Style::SERIF) {
adjustHane();
//adjustMage(sets);
//adjustTate(sets);
//adjustKakato(sets);
//adjustUroko(sets);
//adjustUroko2(sets);
//adjustKirikuchi(sets);
}
}

/// @todo [urgent] to Svg

return r;
namespace {

template <auto... Vals>
bool isIn(auto x)
{
return ((x == Vals) || ...);
}

}


void kage::Glyph::adjustHane()
{
for (auto& line : lines) {
if (isIn<1, 2, 6>(line.d[0]) && line.d[2] == 4) {
int lpx, lpy; // lastPointX/Y
if (line[0] == 1) {
lpx = *line.d[5];
lpy = *line.d[6];
} else if (line[0] == 2){
lpx = *line[7];
lpy = *line[8];
} else {
lpx = *line[9];
lpy = *line[10];
}
static constexpr auto TOO_BIG = std::numeric_limits<int>::max();
int mn = TOO_BIG; // mostNear
if (lpx + 18 < 100) {
mn = lpx + 18;
}
for (auto& lineJ : lines) {
if (&line != &lineJ
&& lineJ[0] == 1 && lineJ[3] == lineJ[5] && lineJ[3] < lpx
&& lineJ[4] <= lpy && lineJ[6] >= lpy) {
if (lpx - *lineJ[3] < 100) {
mn = std::min(mn, lpx - *lineJ[3]);
}
}
}
if(mn != TOO_BIG){
line[2] += 700 - (mn / 15) * 100; // 0-99 -> 0-700
}
}
}
}


Expand Down Expand Up @@ -156,17 +211,13 @@ namespace {
} // anon namespace


kage::Glyph kage::toGlyph(std::string_view source, const SourceEngine& engine)
{
Glyph r;
appendGlyph(r, source, engine);
return r;
}

std::string kage::toSvg(
kage::Glyph kage::toGlyph(
std::string_view source,
const SourceEngine& engine,
const GlyphSets& sets)
{
return toGlyph(source, engine).toSvg(sets);
Glyph r;
appendGlyph(r, source, engine);
r.adjustStrokes(sets);
return r;
}
14 changes: 10 additions & 4 deletions GlyphWiki2/KageLibs/kage.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ namespace kage {
struct Line {
using T = MaybeInt<int>;
Fix1d<T, LINE_SIZE> d;

auto& operator[](unsigned i) { return d[i]; }
auto& operator[](unsigned i) const { return d[i]; }
};

enum class Style { SANS, SERIF };
Expand Down Expand Up @@ -73,13 +76,16 @@ namespace kage {
int kAdjustMageStep = 5;
};

struct Glyph {
struct Glyph
{
public:
SafeVector<Line> lines;
std::string toSvg(const GlyphSets& sets) const;
void adjustStrokes(const GlyphSets& sets);
private:
void adjustHane();
};

Glyph toGlyph(std::string_view source, const SourceEngine& engine);
std::string toSvg(
Glyph toGlyph(
std::string_view source,
const SourceEngine& engine,
const GlyphSets& sets);
Expand Down
22 changes: 22 additions & 0 deletions GlyphWiki2/KageLibs/kageQt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "kageQt.h"


void kage::draw(const GlyphSets& sets, QPaintDevice& target,
MaybeInt<int> a1, MaybeInt<int> a2, MaybeInt<int> a3,
MaybeInt<int> x1, MaybeInt<int> y1,
MaybeInt<int> x2, MaybeInt<int> y2,
MaybeInt<int> x3, MaybeInt<int> y3,
MaybeInt<int> x4, MaybeInt<int> y4)
{

}


void kage::draw(const Glyph& glyph, const GlyphSets& sets, QPaintDevice& target)
{
for (auto v : glyph.lines) {
draw(sets, target,
v[0], v[1], v[2], v[3], v[4], v[5], v[6],
v[7], v[8], v[9], v[10]);
}
}
17 changes: 17 additions & 0 deletions GlyphWiki2/KageLibs/kageQt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "kage.h"

class QPaintDevice;

namespace kage {
void draw(const GlyphSets& sets, QPaintDevice& target,
MaybeInt<int> a1, MaybeInt<int> a2, MaybeInt<int> a3,
MaybeInt<int> x1, MaybeInt<int> y1,
MaybeInt<int> x2, MaybeInt<int> y2,
MaybeInt<int> x3, MaybeInt<int> y3,
MaybeInt<int> x4, MaybeInt<int> y4);
void draw(const Glyph& glyph, const GlyphSets& sets,
QPaintDevice& target);

}
65 changes: 56 additions & 9 deletions GlyphWiki2/KageLibs/u_MaybeInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,30 @@ struct MaybeInt

constexpr MaybeInt() noexcept = default;
constexpr MaybeInt(const MaybeInt&) noexcept = default;
constexpr MaybeInt(T y) noexcept : x(y) {}
constexpr MaybeInt(T y) noexcept : v(y) {}

constexpr MaybeInt& operator = (const This& y) noexcept = default;
constexpr MaybeInt& operator = (T y) noexcept { x = y; return *this; }
constexpr MaybeInt& operator = (T y) noexcept { v = y; return *this; }

constexpr T rawValue() const { return x; }
constexpr T rawValue() const { return v; }
constexpr T operator * ();

constexpr bool hasValue() const { return (x != NO_VALUE); }
constexpr T valueOr(T y) const { return hasValue() ? x : y; }
constexpr bool hasValue() const { return (v != NO_VALUE); }
constexpr T valueOr(T y) const { return hasValue() ? v : y; }
explicit operator bool() const { return hasValue(); }

bool operator == (const This& y) const noexcept = default;
bool operator == (T y) const noexcept { return (hasValue() && (v == y)); }
std::partial_ordering operator <=> (const This& y) const noexcept;
std::partial_ordering operator <=> (T y) const noexcept;

This& operator += (T y);
This& operator += (const This& y);

static This fromStr(std::string_view y);
private:
static constexpr T NO_VALUE = IS_SIGNED ? std::numeric_limits<T>::min() : std::numeric_limits<T>::max();
T x = NO_VALUE;
T v = NO_VALUE;
};


Expand All @@ -46,7 +53,7 @@ constexpr T MaybeInt<T>::operator * ()
{
if (!hasValue())
throw std::logic_error("[MaybeInt::op*] No value!");
return x;
return v;
}


Expand All @@ -57,9 +64,49 @@ auto MaybeInt<T>::fromStr(std::string_view y) -> This
auto q = std::from_chars(
std::to_address(y.begin()),
std::to_address(y.end()),
r.x);
r.v);
if (q.ec != std::errc{}) {
r.x = NO_VALUE;
r.v = NO_VALUE;
}
return r;
}


template <class T>
std::partial_ordering MaybeInt<T>::operator <=> (const This& y) const noexcept
{
if (hasValue() && y.hasValue()) {
return (v <=> y.v);
} else {
return std::partial_ordering::unordered;
}
}


template <class T>
std::partial_ordering MaybeInt<T>::operator <=> (T y) const noexcept
{
if (hasValue()) {
return (v <=> y);
} else {
return std::partial_ordering::unordered;
}
}


template <class T>
auto MaybeInt<T>::operator += (T y) -> This&
{
if (hasValue())
v += y;
return *this;
}


template <class T>
auto MaybeInt<T>::operator += (const This& y) -> This&
{
if (hasValue() && y.hasValue())
v += y.v;
return *this;
}

0 comments on commit dc1bced

Please sign in to comment.