mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
fix image size and GenerateImg method
This commit is contained in:
@ -7,15 +7,15 @@
|
||||
#include "../../../../DesktopEditor/common/Directory.h"
|
||||
#include "../../../../PdfFile/PdfFile.h"
|
||||
|
||||
std::vector<Point> drawCircle1(int n, double cx, double cy, double r) {
|
||||
std::vector<Point> res;
|
||||
for (int i = 0; i < n; i++) {
|
||||
double x = cx + r * cos(i * 8 * atan(1) / n);
|
||||
double y = cy + r * sin(i * 8 * atan(1) / n);
|
||||
res.push_back({x, y});
|
||||
}
|
||||
return res;
|
||||
}
|
||||
// std::vector<Point> drawCircle1(int n, double cx, double cy, double r) {
|
||||
// std::vector<Point> res;
|
||||
// for (int i = 0; i < n; i++) {
|
||||
// double x = cx + r * cos(i * 8 * atan(1) / n);
|
||||
// double y = cy + r * sin(i * 8 * atan(1) / n);
|
||||
// res.push_back({x, y});
|
||||
// }
|
||||
// return res;
|
||||
// }
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
@ -25,7 +25,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->lable_test->setStyleSheet("QLabel { background-color : white;}");
|
||||
points = {{0, 0}, {105, 0}, {105, 105}, {0, 105}};
|
||||
points = {{0, 0}, {500, 0}, {500, 500}, {0, 500}};
|
||||
ui->stackedWidget->setCurrentIndex(0);
|
||||
ui->statusbar->showMessage("Linear");
|
||||
}
|
||||
@ -37,14 +37,17 @@ MainWindow::~MainWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void CleanupFunction(void* data) {
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
void GenerateImg(QImage &img, std::vector<Point> &points, Info &info) {
|
||||
QImage GenerateImg(std::vector<Point> &points, Info &info) {
|
||||
|
||||
NSGraphics::IGraphicsRenderer* pRasterRenderer = NSGraphics::Create();
|
||||
NSFonts::IFontManager *fmp = NSFonts::NSFontManager::Create();
|
||||
pRasterRenderer->SetFontManager(fmp);
|
||||
int nRasterW = img.size().width();
|
||||
int nRasterH = img.size().height();
|
||||
int nRasterW = 500;
|
||||
int nRasterH = 500;
|
||||
BYTE* pData = new BYTE[4 * nRasterW * nRasterH];
|
||||
|
||||
unsigned int back = 0xffffff;
|
||||
@ -61,16 +64,15 @@ void GenerateImg(QImage &img, std::vector<Point> &points, Info &info) {
|
||||
oFrame.put_Stride(4 * nRasterW);
|
||||
|
||||
pRasterRenderer->CreateFromBgraFrame(&oFrame);
|
||||
pRasterRenderer->SetSwapRGB(true);
|
||||
pRasterRenderer->SetSwapRGB(false);
|
||||
|
||||
double dW_MM = nRasterW * 25.4 / 96;
|
||||
double dH_MM = nRasterH * 25.4 / 96;
|
||||
double dW_MM = nRasterW /** 25.4 / 96*/;
|
||||
double dH_MM = nRasterH /** 25.4 / 96*/;
|
||||
|
||||
pRasterRenderer->put_Width(dW_MM);
|
||||
pRasterRenderer->put_Height(dH_MM);
|
||||
|
||||
NSStructures::GradientInfo ginfo = info.ginfo;
|
||||
//ginfo.reflected = true;
|
||||
ginfo.shading.f_type = NSStructures::ShadingInfo::UseNew;
|
||||
pRasterRenderer->put_BrushGradInfo(ginfo);
|
||||
auto a = info.c;
|
||||
@ -89,15 +91,12 @@ void GenerateImg(QImage &img, std::vector<Point> &points, Info &info) {
|
||||
}
|
||||
}
|
||||
pRasterRenderer->Fill();
|
||||
//pRasterRenderer->DrawPath(c_nStroke);
|
||||
pRasterRenderer->EndCommand(c_nPathType);
|
||||
pRasterRenderer->PathCommandEnd();
|
||||
pData32 = (unsigned int*)pData;
|
||||
for (long i = 0; i < img.size().height(); i++) {
|
||||
for (long j = 0; j < img.size().width(); j++) {
|
||||
img.setPixelColor(j, i, QColor(pData32[j + i * nRasterW]));
|
||||
}
|
||||
}
|
||||
|
||||
QImage img = QImage(pData, 500, 500, QImage::Format_RGBA8888, CleanupFunction);
|
||||
oFrame.put_Data(NULL);
|
||||
return img;
|
||||
}
|
||||
|
||||
void MainWindow::on_actionLinear_Gradient_triggered()
|
||||
@ -219,8 +218,7 @@ void MainWindow::on_pushButton_clicked()
|
||||
info.ginfo.shading.function.set_linear_interpolation({0xfff39189, 0xff046582}, {0.0f, 1.0f});
|
||||
}
|
||||
|
||||
QImage pm(400, 400, QImage::Format_RGB888);
|
||||
GenerateImg(pm, points, info);
|
||||
QImage pm = GenerateImg(points, info);
|
||||
ui->lable_test->setPixmap(QPixmap::fromImage(pm));
|
||||
ui->lable_test->setScaledContents(true);
|
||||
}
|
||||
@ -249,3 +247,92 @@ void MainWindow::on_Continue_Shading_Backward_2_clicked(bool checked)
|
||||
info.cont_b = checked;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_First_X_Coordinate_Input_editingFinished()
|
||||
{
|
||||
if (ui->First_X_Coordinate_Input->text().toInt() < 0)
|
||||
ui->First_X_Coordinate_Input->setText("0");
|
||||
if (ui->First_X_Coordinate_Input->text().toInt() > 500)
|
||||
ui->First_X_Coordinate_Input->setText("500");
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_First_Y_Coordinate_Input_editingFinished()
|
||||
{
|
||||
if (ui->First_Y_Coordinate_Input->text().toInt() < 0)
|
||||
ui->First_Y_Coordinate_Input->setText("0");
|
||||
if (ui->First_Y_Coordinate_Input->text().toInt() > 500)
|
||||
ui->First_Y_Coordinate_Input->setText("500");
|
||||
}
|
||||
|
||||
void MainWindow::on_Second_X_Coordinate_Input_editingFinished()
|
||||
{
|
||||
if (ui->Second_X_Coordinate_Input->text().toInt() < 0)
|
||||
ui->Second_X_Coordinate_Input->setText("0");
|
||||
if (ui->Second_X_Coordinate_Input->text().toInt() > 500)
|
||||
ui->Second_X_Coordinate_Input->setText("500");
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_Second_Y_Coordinate_Input_editingFinished()
|
||||
{
|
||||
if (ui->Second_Y_Coordinate_Input->text().toInt() < 0)
|
||||
ui->Second_Y_Coordinate_Input->setText("0");
|
||||
if (ui->Second_Y_Coordinate_Input->text().toInt() > 500)
|
||||
ui->Second_Y_Coordinate_Input->setText("500");
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_First_Center_X_Coordinate_Input_editingFinished()
|
||||
{
|
||||
if (ui->First_Center_X_Coordinate_Input->text().toInt() < 0)
|
||||
ui->First_Center_X_Coordinate_Input->setText("0");
|
||||
if (ui->First_Center_X_Coordinate_Input->text().toInt() > 499)
|
||||
ui->First_Center_X_Coordinate_Input->setText("500");
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_First_Center_Y_Coordinate_Input_editingFinished()
|
||||
{
|
||||
if (ui->First_Center_Y_Coordinate_Input->text().toInt() < 0)
|
||||
ui->First_Center_Y_Coordinate_Input->setText("0");
|
||||
if (ui->First_Center_Y_Coordinate_Input->text().toInt() > 499)
|
||||
ui->First_Center_Y_Coordinate_Input->setText("500");
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_Second_Center_X_Coordinate_Input_editingFinished()
|
||||
{
|
||||
if (ui->Second_Center_X_Coordinate_Input->text().toInt() < 0)
|
||||
ui->Second_Center_X_Coordinate_Input->setText("0");
|
||||
if (ui->Second_Center_X_Coordinate_Input->text().toInt() > 500)
|
||||
ui->Second_Center_X_Coordinate_Input->setText("500");
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_Second_Center_Y_Coordinate_Input_editingFinished()
|
||||
{
|
||||
if (ui->Second_Center_Y_Coordinate_Input->text().toInt() < 0)
|
||||
ui->Second_Center_Y_Coordinate_Input->setText("0");
|
||||
if (ui->Second_Center_Y_Coordinate_Input->text().toInt() > 500)
|
||||
ui->Second_Center_Y_Coordinate_Input->setText("500");
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_First_Radius_Input_editingFinished()
|
||||
{
|
||||
if (ui->First_Radius_Input->text().toInt() < 0)
|
||||
ui->First_Radius_Input->setText("0");
|
||||
if (ui->First_Radius_Input->text().toInt() > 500)
|
||||
ui->First_Radius_Input->setText("500");
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_Second_Radius_Input_editingFinished()
|
||||
{
|
||||
if (ui->Second_Radius_Input->text().toInt() < 0)
|
||||
ui->Second_Radius_Input->setText("0");
|
||||
if (ui->Second_Radius_Input->text().toInt() > 500)
|
||||
ui->Second_Radius_Input->setText("500");
|
||||
}
|
||||
|
||||
|
||||
@ -72,7 +72,7 @@ struct Info {
|
||||
}
|
||||
};
|
||||
|
||||
void GenerateImg(QImage &img, int grad = 1,double angle = 0,std::vector<Point> points = {});
|
||||
QImage GenerateImg(int grad = 1,double angle = 0,std::vector<Point> points = {});
|
||||
std::vector<Point> drawCircle1(int n, double cx, double cy, double r);
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
@ -110,6 +110,26 @@ private slots:
|
||||
|
||||
void on_Continue_Shading_Backward_2_clicked(bool checked);
|
||||
|
||||
void on_First_X_Coordinate_Input_editingFinished();
|
||||
|
||||
void on_First_Y_Coordinate_Input_editingFinished();
|
||||
|
||||
void on_Second_X_Coordinate_Input_editingFinished();
|
||||
|
||||
void on_Second_Y_Coordinate_Input_editingFinished();
|
||||
|
||||
void on_First_Center_X_Coordinate_Input_editingFinished();
|
||||
|
||||
void on_First_Center_Y_Coordinate_Input_editingFinished();
|
||||
|
||||
void on_Second_Center_X_Coordinate_Input_editingFinished();
|
||||
|
||||
void on_Second_Center_Y_Coordinate_Input_editingFinished();
|
||||
|
||||
void on_First_Radius_Input_editingFinished();
|
||||
|
||||
void on_Second_Radius_Input_editingFinished();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user