Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
a7660331a
tesseract
提交
62feabf5
T
tesseract
项目概览
a7660331a
/
tesseract
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
tesseract
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
62feabf5
编写于
12月 22, 2021
作者:
S
Stefan Weil
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use fmtlib for ScrollView::SendMsg
Signed-off-by:
N
Stefan Weil
<
sw@weilnetz.de
>
上级
f22cdad0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
35 deletion
+31
-35
src/viewer/scrollview.cpp
src/viewer/scrollview.cpp
+26
-30
src/viewer/scrollview.h
src/viewer/scrollview.h
+5
-5
未找到文件。
src/viewer/scrollview.cpp
浏览文件 @
62feabf5
...
...
@@ -391,19 +391,15 @@ ScrollView::~ScrollView() {
#ifndef GRAPHICS_DISABLED
/// Send a message to the server, attaching the window id.
void
ScrollView
::
SendMsg
(
const
char
*
format
,
...)
{
void
ScrollView
::
vSendMsg
(
fmt
::
string_view
format
,
fmt
::
format_args
args
)
{
auto
message
=
fmt
::
vformat
(
format
,
args
);
if
(
!
points_
->
empty
)
{
SendPolygon
();
}
va_list
args
;
char
message
[
kMaxMsgSize
-
4
];
va_start
(
args
,
format
);
// variable list
vsnprintf
(
message
,
sizeof
(
message
),
format
,
args
);
va_end
(
args
);
char
form
[
kMaxMsgSize
];
snprintf
(
form
,
sizeof
(
form
),
"w%u:%s
\n
"
,
window_id_
,
message
);
snprintf
(
form
,
sizeof
(
form
),
"w%u:%s
\n
"
,
window_id_
,
message
.
c_str
()
);
stream_
->
Send
(
form
);
}
...
...
@@ -550,7 +546,7 @@ void ScrollView::vAddMessage(fmt::string_view format, fmt::format_args args) {
snprintf
(
form
,
sizeof
(
form
),
"w%u:%s"
,
window_id_
,
message
.
c_str
());
char
*
esc
=
AddEscapeChars
(
form
);
SendMsg
(
"addMessage(
\"
%s
\"
)"
,
esc
);
SendMsg
(
"addMessage(
\"
{}
\"
)"
,
esc
);
delete
[]
esc
;
}
...
...
@@ -572,7 +568,7 @@ void ScrollView::Clear() {
// Set the stroke width.
void
ScrollView
::
Stroke
(
float
width
)
{
SendMsg
(
"setStrokeWidth(
%f
)"
,
width
);
SendMsg
(
"setStrokeWidth(
{}
)"
,
width
);
}
// Draw a rectangle using the current pen color.
...
...
@@ -581,33 +577,33 @@ void ScrollView::Rectangle(int x1, int y1, int x2, int y2) {
if
(
x1
==
x2
&&
y1
==
y2
)
{
return
;
// Scrollviewer locks up.
}
SendMsg
(
"drawRectangle(
%d,%d,%d,%d
)"
,
x1
,
TranslateYCoordinate
(
y1
),
x2
,
TranslateYCoordinate
(
y2
));
SendMsg
(
"drawRectangle(
{},{},{},{}
)"
,
x1
,
TranslateYCoordinate
(
y1
),
x2
,
TranslateYCoordinate
(
y2
));
}
// Draw an ellipse using the current pen color.
// The ellipse is filled with the current brush color.
void
ScrollView
::
Ellipse
(
int
x1
,
int
y1
,
int
width
,
int
height
)
{
SendMsg
(
"drawEllipse(
%d,%d,%u,%u
)"
,
x1
,
TranslateYCoordinate
(
y1
),
width
,
height
);
SendMsg
(
"drawEllipse(
{},{},{},{}
)"
,
x1
,
TranslateYCoordinate
(
y1
),
width
,
height
);
}
// Set the pen color to the given RGB values.
void
ScrollView
::
Pen
(
int
red
,
int
green
,
int
blue
)
{
SendMsg
(
"pen(
%d,%d,%d
)"
,
red
,
green
,
blue
);
SendMsg
(
"pen(
{},{},{}
)"
,
red
,
green
,
blue
);
}
// Set the pen color to the given RGB values.
void
ScrollView
::
Pen
(
int
red
,
int
green
,
int
blue
,
int
alpha
)
{
SendMsg
(
"pen(
%d,%d,%d,%d
)"
,
red
,
green
,
blue
,
alpha
);
SendMsg
(
"pen(
{},{},{},{}
)"
,
red
,
green
,
blue
,
alpha
);
}
// Set the brush color to the given RGB values.
void
ScrollView
::
Brush
(
int
red
,
int
green
,
int
blue
)
{
SendMsg
(
"brush(
%d,%d,%d
)"
,
red
,
green
,
blue
);
SendMsg
(
"brush(
{},{},{}
)"
,
red
,
green
,
blue
);
}
// Set the brush color to the given RGB values.
void
ScrollView
::
Brush
(
int
red
,
int
green
,
int
blue
,
int
alpha
)
{
SendMsg
(
"brush(
%d,%d,%d,%d
)"
,
red
,
green
,
blue
,
alpha
);
SendMsg
(
"brush(
{},{},{},{}
)"
,
red
,
green
,
blue
,
alpha
);
}
// Set the attributes for future Text(..) calls.
...
...
@@ -632,18 +628,18 @@ void ScrollView::TextAttributes(const char *font, int pixel_size, bool bold, boo
}
else
{
u
=
"false"
;
}
SendMsg
(
"textAttributes('
%s',%u,%s,%s,%s
)"
,
font
,
pixel_size
,
b
,
i
,
u
);
SendMsg
(
"textAttributes('
{}',{},{},{},{}
)"
,
font
,
pixel_size
,
b
,
i
,
u
);
}
// Draw text at the given coordinates.
void
ScrollView
::
Text
(
int
x
,
int
y
,
const
char
*
mystring
)
{
SendMsg
(
"drawText(
%d,%d,'%s
')"
,
x
,
TranslateYCoordinate
(
y
),
mystring
);
SendMsg
(
"drawText(
{},{},'{}
')"
,
x
,
TranslateYCoordinate
(
y
),
mystring
);
}
// Open and draw an image given a name at (x,y).
void
ScrollView
::
Draw
(
const
char
*
image
,
int
x_pos
,
int
y_pos
)
{
SendMsg
(
"openImage('
%s
')"
,
image
);
SendMsg
(
"drawImage('
%s',%d,%d
)"
,
image
,
x_pos
,
TranslateYCoordinate
(
y_pos
));
SendMsg
(
"openImage('
{}
')"
,
image
);
SendMsg
(
"drawImage('
{}',{},{}
)"
,
image
,
x_pos
,
TranslateYCoordinate
(
y_pos
));
}
// Add new checkboxmenuentry to menubar.
...
...
@@ -652,9 +648,9 @@ void ScrollView::MenuItem(const char *parent, const char *name, int cmdEvent, bo
parent
=
""
;
}
if
(
flag
)
{
SendMsg
(
"addMenuBarItem('
%s','%s',%d
,true)"
,
parent
,
name
,
cmdEvent
);
SendMsg
(
"addMenuBarItem('
{}','{}',{}
,true)"
,
parent
,
name
,
cmdEvent
);
}
else
{
SendMsg
(
"addMenuBarItem('
%s','%s',%d
,false)"
,
parent
,
name
,
cmdEvent
);
SendMsg
(
"addMenuBarItem('
{}','{}',{}
,false)"
,
parent
,
name
,
cmdEvent
);
}
}
...
...
@@ -663,7 +659,7 @@ void ScrollView::MenuItem(const char *parent, const char *name, int cmdEvent) {
if
(
parent
==
nullptr
)
{
parent
=
""
;
}
SendMsg
(
"addMenuBarItem('
%s','%s',%d
)"
,
parent
,
name
,
cmdEvent
);
SendMsg
(
"addMenuBarItem('
{}','{}',{}
)"
,
parent
,
name
,
cmdEvent
);
}
// Add new submenu to menubar.
...
...
@@ -671,7 +667,7 @@ void ScrollView::MenuItem(const char *parent, const char *name) {
if
(
parent
==
nullptr
)
{
parent
=
""
;
}
SendMsg
(
"addMenuBarItem('
%s','%s
')"
,
parent
,
name
);
SendMsg
(
"addMenuBarItem('
{}','{}
')"
,
parent
,
name
);
}
// Add new submenu to popupmenu.
...
...
@@ -679,7 +675,7 @@ void ScrollView::PopupItem(const char *parent, const char *name) {
if
(
parent
==
nullptr
)
{
parent
=
""
;
}
SendMsg
(
"addPopupMenuItem('
%s','%s
')"
,
parent
,
name
);
SendMsg
(
"addPopupMenuItem('
{}','{}
')"
,
parent
,
name
);
}
// Add new submenuentry to popupmenu.
...
...
@@ -690,7 +686,7 @@ void ScrollView::PopupItem(const char *parent, const char *name, int cmdEvent, c
}
char
*
esc
=
AddEscapeChars
(
value
);
char
*
esc2
=
AddEscapeChars
(
desc
);
SendMsg
(
"addPopupMenuItem('
%s','%s',%d,'%s','%s
')"
,
parent
,
name
,
cmdEvent
,
esc
,
esc2
);
SendMsg
(
"addPopupMenuItem('
{}','{}',{},'{}','{}
')"
,
parent
,
name
,
cmdEvent
,
esc
,
esc2
);
delete
[]
esc
;
delete
[]
esc2
;
}
...
...
@@ -724,7 +720,7 @@ void ScrollView::Brush(Color color) {
// Shows a modal Input Dialog which can return any kind of String
char
*
ScrollView
::
ShowInputDialog
(
const
char
*
msg
)
{
SendMsg
(
"showInputDialog(
\"
%s
\"
)"
,
msg
);
SendMsg
(
"showInputDialog(
\"
{}
\"
)"
,
msg
);
SVEvent
*
ev
;
// wait till an input event (all others are thrown away)
ev
=
AwaitEvent
(
SVET_INPUT
);
...
...
@@ -736,7 +732,7 @@ char *ScrollView::ShowInputDialog(const char *msg) {
// Shows a modal Yes/No Dialog which will return 'y' or 'n'
int
ScrollView
::
ShowYesNoDialog
(
const
char
*
msg
)
{
SendMsg
(
"showYesNoDialog(
\"
%s
\"
)"
,
msg
);
SendMsg
(
"showYesNoDialog(
\"
{}
\"
)"
,
msg
);
SVEvent
*
ev
;
// Wait till an input event (all others are thrown away)
ev
=
AwaitEvent
(
SVET_INPUT
);
...
...
@@ -750,7 +746,7 @@ int ScrollView::ShowYesNoDialog(const char *msg) {
void
ScrollView
::
ZoomToRectangle
(
int
x1
,
int
y1
,
int
x2
,
int
y2
)
{
y1
=
TranslateYCoordinate
(
y1
);
y2
=
TranslateYCoordinate
(
y2
);
SendMsg
(
"zoomRectangle(
%d,%d,%d,%d
)"
,
std
::
min
(
x1
,
x2
),
std
::
min
(
y1
,
y2
),
std
::
max
(
x1
,
x2
),
SendMsg
(
"zoomRectangle(
{},{},{},{}
)"
,
std
::
min
(
x1
,
x2
),
std
::
min
(
y1
,
y2
),
std
::
max
(
x1
,
x2
),
std
::
max
(
y1
,
y2
));
}
...
...
@@ -761,7 +757,7 @@ void ScrollView::Draw(Image image, int x_pos, int y_pos) {
pixWriteMem
(
&
data
,
&
size
,
image
,
IFF_PNG
);
int
base64_len
=
(
size
+
2
)
/
3
*
4
;
y_pos
=
TranslateYCoordinate
(
y_pos
);
SendMsg
(
"readImage(
%d,%d,%d
)"
,
x_pos
,
y_pos
,
base64_len
);
SendMsg
(
"readImage(
{},{},{}
)"
,
x_pos
,
y_pos
,
base64_len
);
// Base64 encode the data.
const
char
kBase64Table
[
64
]
=
{
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
,
'G'
,
'H'
,
'I'
,
'J'
,
'K'
,
'L'
,
'M'
,
'N'
,
'O'
,
'P'
,
...
...
src/viewer/scrollview.h
浏览文件 @
62feabf5
...
...
@@ -41,10 +41,6 @@
namespace
tesseract
{
#if !defined(__GNUC__) && !defined(__attribute__)
# define __attribute__(attr) // compiler without support for __attribute__
#endif
class
ScrollView
;
class
SVNetwork
;
class
SVSemaphore
;
...
...
@@ -315,7 +311,11 @@ public:
// this just for fun will likely break your application!
// It is public so you can actually take use of the LUA functionalities, but
// be careful!
void
SendMsg
(
const
char
*
msg
,
...)
__attribute__
((
format
(
printf
,
2
,
3
)));
void
vSendMsg
(
fmt
::
string_view
format
,
fmt
::
format_args
args
);
template
<
typename
S
,
typename
...
Args
>
void
SendMsg
(
const
S
&
format
,
Args
&&
...
args
)
{
vSendMsg
(
format
,
fmt
::
make_args_checked
<
Args
...
>
(
format
,
args
...));
}
// Custom messages (manipulating java code directly) can be send through this.
// Send a message to the server without adding the
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录