-
Notifications
You must be signed in to change notification settings - Fork 1
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
22 changed files
with
3,068 additions
and
1,286 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
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,4 @@ | ||
.vs/ | ||
Release/ | ||
Debug/ | ||
x64/ |
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,138 @@ | ||
#pragma once | ||
#include <cstdint> | ||
#include <string> | ||
|
||
struct COLOR { | ||
DWORD c; | ||
COLOR(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0) : | ||
c(a<<24|b<<16|g<<8|r) { } | ||
COLOR(DWORD c) :c(c) {} | ||
operator DWORD() {return c;} | ||
}; | ||
|
||
class GDIUtil | ||
{ | ||
public: | ||
static void fill(HDC hdc, COLOR color, int left, int top, int width, int height) { | ||
if (width == 0 || height == 0) | ||
return; | ||
RECT rc = { left, top, left + width, top + height }; | ||
SetBkColor(hdc, color); | ||
ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL); | ||
} | ||
|
||
static void line(HDC hdc, COLOR color, int x1, int y1, int x2, int y2) | ||
{ | ||
_ASSERT(x1 != x2 || y1 != y2); | ||
HPEN hp = CreatePen(BS_SOLID, 1, color); | ||
HGDIOBJ ho = SelectObject(hdc, hp); | ||
MoveToEx(hdc, x1, y1, NULL); | ||
LineTo(hdc, x2, y2); | ||
SelectObject(hdc, ho); | ||
DeleteObject(hp); | ||
} | ||
}; | ||
|
||
class MemDC { | ||
HDC hdc; | ||
HDC compatibleDC; | ||
HBITMAP bmp; | ||
HBITMAP oldBmp; | ||
|
||
public: | ||
|
||
MemDC(HDC hdc, int width, int height) :hdc(hdc) { | ||
compatibleDC = CreateCompatibleDC(NULL); | ||
|
||
bmp = CreateCompatibleBitmap(hdc, width, height); | ||
oldBmp = (HBITMAP)SelectObject(compatibleDC, bmp); | ||
} | ||
|
||
operator HDC() const { return compatibleDC; } | ||
|
||
~MemDC() { | ||
SelectObject(compatibleDC, oldBmp); | ||
DeleteObject(oldBmp); | ||
DeleteObject(bmp); | ||
DeleteDC(compatibleDC); | ||
} | ||
}; | ||
|
||
struct CharStyle | ||
{ | ||
uint8_t bold : 1; | ||
uint8_t itatic : 1; | ||
uint8_t underline : 1; | ||
uint8_t reserved : 5; | ||
}; | ||
|
||
const CharStyle default_style = { 0 }; | ||
|
||
class Font { | ||
HFONT hf; | ||
HGDIOBJ ho; | ||
HDC hdc; | ||
const unsigned int format = DT_NOPREFIX | DT_WORDBREAK | DT_EDITCONTROL | DT_NOCLIP | DT_HIDEPREFIX; | ||
|
||
public: | ||
COLOR color; | ||
CharStyle style; | ||
|
||
Font(int size, LPCTSTR fontname, COLOR color = 0x00000000, CharStyle style = default_style) | ||
:color(color), | ||
style(style) | ||
{ | ||
hf = CreateFont(size, 0, 0, 0, style.bold ? 700 : 400, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, | ||
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_SWISS, fontname); | ||
} | ||
|
||
Font& bind(HDC hdc) { | ||
this->hdc = hdc; | ||
ho = SelectObject(hdc, hf); | ||
return *this; | ||
} | ||
|
||
void unbind() { | ||
SelectObject(hdc, ho); | ||
} | ||
|
||
//// calc expected height for specific text width | ||
//int calcHeight(const std::wstring& str, int width) | ||
//{ | ||
// RECT rc = { 0,0,width,0 }; | ||
// DrawTextW(hdc, str.c_str(), str.length(), &rc, format | DT_CALCRECT); | ||
// return rc.bottom - rc.top; | ||
//} | ||
|
||
//Font& drawText(const std::wstring& str, int left, int top, int width, int height) { | ||
// RECT rc = { left, top, left + width, top + height }; | ||
|
||
// SetBkMode(hdc, TRANSPARENT); | ||
// SetTextColor(hdc, color); | ||
|
||
// DrawTextW(hdc, str.c_str(), str.length(), &rc, format); | ||
// return *this; | ||
//} | ||
|
||
// Print a line without '\n' | ||
Font& printLine(const std::wstring& str, int left, int top) { | ||
_ASSERT(str.find(L'\n') == std::string::npos); | ||
|
||
SetBkMode(hdc, TRANSPARENT); | ||
SetTextColor(hdc, color); | ||
|
||
std::wstring temp; | ||
for (wchar_t c : str) | ||
if (c != L'\t') | ||
temp += c; | ||
else | ||
temp += L" "; | ||
|
||
TextOutW(hdc, left, top, temp.c_str(), temp.length()); | ||
return *this; | ||
} | ||
|
||
~Font() { | ||
DeleteObject(hf); | ||
} | ||
}; |
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,31 @@ | ||
#pragma once | ||
#include "lex_parse.h" | ||
#include <sstream> | ||
#include <regex> | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include <iomanip> | ||
#ifdef _DEBUG | ||
#define SHOW_PARSING_TIME | ||
#endif | ||
void parse_markdown(std::wstring& str) | ||
{ | ||
//std::wregex regex_table_align(L"^([:\\s]?-+[:\\s]?\\|?)+$"); | ||
//bool re = std::regex_match(str, regex_table_align); | ||
//int j = 5; | ||
#ifdef SHOW_PARSING_TIME | ||
clock_t begin = clock(); | ||
#endif | ||
|
||
std::wostringstream wos; | ||
|
||
auto scanned = scanner(str); | ||
parse_fromlex(wos, std::begin(scanned), std::end(scanned)); | ||
|
||
#ifdef SHOW_PARSING_TIME | ||
clock_t end = clock(); | ||
double t = double(end - begin) / CLOCKS_PER_SEC; | ||
wos << L"<br><p>用时:" << std::setprecision(2) << t << L" s</p>"; | ||
#endif // SHOW_PARSING_TIME | ||
str = wos.str(); | ||
} |
Binary file not shown.
Binary file not shown.
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,28 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25420.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MyNotePad", "MyNotePad.vcxproj", "{69CA1588-7FCD-436F-9507-ABEB8A6F636D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Debug|x64.ActiveCfg = Debug|x64 | ||
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Debug|x64.Build.0 = Debug|x64 | ||
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Debug|x86.Build.0 = Debug|Win32 | ||
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Release|x64.ActiveCfg = Release|x64 | ||
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Release|x64.Build.0 = Release|x64 | ||
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Release|x86.ActiveCfg = Release|Win32 | ||
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.