Skip to content

Commit 066795e

Browse files
Up to 1.0.7
* New options to control font boldness (issue #2)
1 parent 2922eb2 commit 066795e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

main.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
#define MAX_COLUMN_COUNT 128
6767
#define MAX_COLUMN_LENGTH 2000
6868
#define APP_NAME TEXT("jsontab")
69-
#define APP_VERSION TEXT("1.0.6")
69+
#define APP_VERSION TEXT("1.0.7")
7070

7171
#define CP_UTF16LE 1200
7272
#define CP_UTF16BE 1201
@@ -95,7 +95,7 @@ LRESULT CALLBACK cbNewText(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
9595
char* json_value_get_as_string(const JSON_Value* val);
9696
char* json_get_path(const JSON_Value* val);
9797
BOOL addNode(HWND hTreeWnd, HTREEITEM hParentItem, JSON_Value* val);
98-
int highlightBlock(HWND hWnd, TCHAR* text, int start);
98+
int highlightBlock(HWND hWnd, TCHAR* text, int start, BOOL useBold);
9999
HWND getMainWindow(HWND hWnd);
100100
void setStoredValue(TCHAR* name, int value);
101101
int getStoredValue(TCHAR* name, int defValue);
@@ -1454,7 +1454,7 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
14541454
SendMessage(hTextWnd, EM_SETSEL, 0, -1);
14551455
SendMessage(hTextWnd, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cf2);
14561456

1457-
highlightBlock(hTextWnd, text, 0);
1457+
highlightBlock(hTextWnd, text, 0, getStoredValue(TEXT("font-use-bold"), 0));
14581458
free(text);
14591459
SendMessage(hTextWnd, EM_SETSEL, 0, 0);
14601460
LockWindowUpdate(0);
@@ -1641,7 +1641,8 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
16411641
*pFontSize += wParam;
16421642
DeleteFont(GetProp(hWnd, TEXT("FONT")));
16431643

1644-
HFONT hFont = CreateFont (*pFontSize, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, (TCHAR*)GetProp(hWnd, TEXT("FONTFAMILY")));
1644+
int weight = getStoredValue(TEXT("font-weight"), 0);
1645+
HFONT hFont = CreateFont (*pFontSize, 0, 0, 0, weight < 0 || weight > 9 ? FW_DONTCARE : weight * 100, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, (TCHAR*)GetProp(hWnd, TEXT("FONTFAMILY")));
16451646
HWND hTreeWnd = GetDlgItem(hWnd, IDC_TREE);
16461647
HWND hTabWnd = GetDlgItem(hWnd, IDC_TAB);
16471648
HWND hGridWnd = GetDlgItem(hTabWnd, IDC_GRID);
@@ -2049,7 +2050,7 @@ BOOL addNode(HWND hTreeWnd, HTREEITEM hParentItem, JSON_Value* val) {
20492050
return TRUE;
20502051
}
20512052

2052-
int highlightBlock(HWND hWnd, TCHAR* text, int start) {
2053+
int highlightBlock(HWND hWnd, TCHAR* text, int start, BOOL useBold) {
20532054
int textLen = _tcslen(text);
20542055
if (start < 0 || start >= textLen || (text[start] != TEXT('{') && text[start] != TEXT('[')))
20552056
return 0;
@@ -2071,7 +2072,7 @@ int highlightBlock(HWND hWnd, TCHAR* text, int start) {
20712072
while (pos < textLen) {
20722073
TCHAR c = text[pos];
20732074
if (c == TEXT('[') || c == TEXT('{')) {
2074-
pos += highlightBlock(hWnd, text, pos);
2075+
pos += highlightBlock(hWnd, text, pos, useBold);
20752076
} else if ((c == TEXT(']') && !isObject) || (c == TEXT('}') && isObject)) {
20762077
break;
20772078
} else if (c == TEXT('"')) {
@@ -2086,7 +2087,7 @@ int highlightBlock(HWND hWnd, TCHAR* text, int start) {
20862087
end++;
20872088

20882089
cf2.crTextColor = isKey ? keyColor : stringColor;
2089-
cf2.dwEffects = isKey ? CFM_BOLD : 0;
2090+
cf2.dwEffects = isKey && useBold ? CFM_BOLD : 0;
20902091
SendMessage(hWnd, EM_SETSEL, pos, end);
20912092
SendMessage(hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
20922093

@@ -2107,7 +2108,7 @@ int highlightBlock(HWND hWnd, TCHAR* text, int start) {
21072108
} else if (_tcsstr(buf, TEXT("null")) == buf) {
21082109
cf2.crTextColor = nullColor;
21092110
end += 4;
2110-
cf2.dwEffects = CFM_BOLD;
2111+
cf2.dwEffects = useBold ? CFM_BOLD : 0;
21112112
}
21122113

21132114
SendMessage(hWnd, EM_SETSEL, pos, end);

0 commit comments

Comments
 (0)