提交 62feabf5 编写于 作者: S Stefan Weil

Use fmtlib for ScrollView::SendMsg

Signed-off-by: NStefan Weil <sw@weilnetz.de>
上级 f22cdad0
......@@ -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',
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册