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;
|
||||
};
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1098</width>
|
||||
<height>706</height>
|
||||
<width>1053</width>
|
||||
<height>602</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -17,16 +17,34 @@
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="lable_test">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>500</width>
|
||||
<height>500</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>500</width>
|
||||
<height>500</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>510</x>
|
||||
<y>-10</y>
|
||||
<width>535</width>
|
||||
<height>511</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>535</width>
|
||||
@ -48,21 +66,9 @@
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>201</width>
|
||||
<height>161</height>
|
||||
<height>150</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>201</width>
|
||||
<height>161</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>201</width>
|
||||
<height>161</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Choose gradient colorspace</string>
|
||||
</property>
|
||||
@ -123,9 +129,9 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>180</y>
|
||||
<y>160</y>
|
||||
<width>511</width>
|
||||
<height>401</height>
|
||||
<height>331</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
@ -314,7 +320,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>380</x>
|
||||
<y>180</y>
|
||||
<y>160</y>
|
||||
<width>131</width>
|
||||
<height>161</height>
|
||||
</rect>
|
||||
@ -355,7 +361,7 @@
|
||||
<x>0</x>
|
||||
<y>10</y>
|
||||
<width>510</width>
|
||||
<height>160</height>
|
||||
<height>140</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
@ -458,7 +464,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>180</y>
|
||||
<y>160</y>
|
||||
<width>371</width>
|
||||
<height>100</height>
|
||||
</rect>
|
||||
@ -517,7 +523,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>290</y>
|
||||
<y>260</y>
|
||||
<width>319</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
@ -530,7 +536,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>310</y>
|
||||
<y>280</y>
|
||||
<width>335</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
@ -543,7 +549,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>330</y>
|
||||
<y>300</y>
|
||||
<width>281</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
@ -568,15 +574,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1098</width>
|
||||
<width>1053</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
||||
Reference in New Issue
Block a user