新增图片加载接口,调整目录结构

This commit is contained in:
2025-04-01 20:42:27 +08:00
parent 4036ee2ded
commit e966dadc70
78 changed files with 159 additions and 33 deletions

View File

@@ -1,14 +1,66 @@
#include <iostream>
#include "mirage.h"
#include "window/mwindow.h"
#include "font/font_system.h"
#include "font/font_renderer/colr_renderer.h"
#include "widget/widget_new.h"
#include "widget/compound_widget/mbutton.h"
#include "widget/leaf_widget/mtext_block.h"
#include "widget/panel_widget/mbox.h"
#include "freetype/freetype.h"
#include "freetype/ftlcdfil.h"
int main(int argc, char* argv[]) {
mirage_app::get().init();
FT_Library ft_library;
if (FT_Init_FreeType(&ft_library)) {
std::cerr << "Failed to initialize FreeType library" << std::endl;
return -1;
}
FT_Library_SetLcdFilter(ft_library, FT_LCD_FILTER_DEFAULT);
FT_Face ft_face;
if (FT_New_Face(ft_library, "C:/Windows/Fonts/msyh.ttc", 0, &ft_face)) {
std::cerr << "Failed to load font face" << std::endl;
return -1;
}
FT_Library_SetLcdFilterWeights(ft_library, nullptr);
FT_Library_SetLcdGeometry(ft_library, nullptr);
FT_Library_SetLcdFilter(ft_library, FT_LCD_FILTER_DEFAULT);
// 渲染一个字符
FT_Set_Pixel_Sizes(ft_face, 0, 24);
FT_Load_Char(ft_face, U'', FT_LOAD_RENDER);
FT_Render_Glyph(ft_face->glyph, FT_RENDER_MODE_LCD);
// 获取渲染的位图
FT_Bitmap bitmap = ft_face->glyph->bitmap;
if (bitmap.buffer) {
std::cout << "Bitmap width: " << bitmap.width << ", height: " << bitmap.rows << std::endl;
} else {
std::cerr << "Failed to get bitmap" << std::endl;
}
// 保存位图到文件
color_emoji_bitmap_t bitmap_;
// 将bitmap数据转换为color_emoji_bitmap_t格式
bitmap_.width = bitmap.width;
bitmap_.height = bitmap.rows;
bitmap_.data.resize(bitmap.width * bitmap.rows * 4); // RGBA格式
for (int y = 0; y < bitmap.rows; ++y) {
for (int x = 0; x < bitmap.width; ++x) {
int index = y * bitmap.width + x;
bitmap_.data[index * 4 + 0] = bitmap.buffer[index]; // R
bitmap_.data[index * 4 + 1] = bitmap.buffer[index]; // G
bitmap_.data[index * 4 + 2] = bitmap.buffer[index]; // B
bitmap_.data[index * 4 + 3] = bitmap.buffer[index]; // A
}
}
save_bitmap("output.bmp", bitmap_);
FT_Done_Face(ft_face);
auto& manager = font_manager::instance();
manager.add_font(L"C:/Users/46944/AppData/Local/Microsoft/Windows/Fonts/MapleMono-NF-CN-Regular.ttf");
manager.add_font(L"C:/Windows/Fonts/msyh.ttc");