Browse Source

offset for vertical centering

isundil 6 years ago
parent
commit
2bc0fbd570
2 changed files with 13 additions and 1 deletions
  1. 1 0
      conf/instaserv.example.conf
  2. 12 1
      src/commands/is_create.cpp

+ 1 - 0
conf/instaserv.example.conf

@@ -23,6 +23,7 @@ module
 	httpRoot = "http://devel.knacki.info/instaserv/"
 	font = "/home/isundil/projects/instaServ/conf/roboto-mono.ttf"
 	fontSize = 12
+	offsetTop = 0
 	quoteTop = 150
 	quoteBottom = 10
 	quoteLeft = 10

+ 12 - 1
src/commands/is_create.cpp

@@ -93,6 +93,7 @@ public:
 	ImageWriter& SetBgColor(long);
 	ImageWriter& SetFgColor(long);
 	ImageWriter& SetFontSize(char);
+	ImageWriter& SetOffsetTop(long);
 	ImageWriter& SetFontPath(const Anope::string &);
 
 	bool Build(User* u);
@@ -103,6 +104,7 @@ protected:
 	Anope::string outputName;
 	ARGB bgColor;
 	RGB fgColor;
+	long offsetTop;
 	size_t top;
 	size_t left;
 	size_t bottom;
@@ -163,6 +165,14 @@ ImageWriter& ImageWriter::SetFgColor(long value)
 	return *this;
 }
 
+ImageWriter& ImageWriter::SetOffsetTop(long value)
+{
+	Log(LOG_DEBUG) << "Offset Top: " << value;
+	offsetTop = value;
+	return *this;
+}
+
+
 ImageWriter& ImageWriter::SetQuotePosition(size_t top, size_t left, size_t right, size_t bottom)
 {
 	Log(LOG_DEBUG) << "Position: " << top << ',' << left << ',' << right << ',' << bottom;
@@ -226,7 +236,7 @@ bool ImageWriter::Build(User *u)
 	TextLines lines(fontSize * 0.55);
 	for (const Anope::string& str: text)
 		WriteDryRun(writer, font, fontSize, str, lines, fgColor);
-	int offsetY = -((top -bottom -lines.getHeight() -lines.getLineSpacing()) /2);
+	int offsetY = -((top +offsetTop -bottom -lines.getHeight() -lines.getLineSpacing()) /2);
 	if (offsetY > 0)
 		offsetY = 0;
 	for (const TextItem& line: lines.lines)
@@ -374,6 +384,7 @@ void InstaMessageBufferImpl::OnEndBuffer()
 	builder.SetBackground(config->Get<Anope::string>("background", ""))
 		.SetText(lines)
 		.SetOutputPath(path)
+		.SetOffsetTop(config->Get<long>("offsetTop", "0"))
 		.SetQuotePosition(
 				config->Get<unsigned>("quoteTop", "0"),
 				config->Get<unsigned>("quoteLeft", "0"),