Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ft2build.h>
- #include FT_FREETYPE_H
- #include FT_LCD_FILTER_H
- #include FT_MODULE_H
- #include FT_TRUETYPE_DRIVER_H
- #include "FileUtility.hpp"
- int main(int argc, char** argv) {
- FT_Library library;
- FT_Error error = FT_Init_FreeType(&library);
- if (error) std::cout << "Freetype init failed!" << std::endl;
- FT_UInt interpreter_version = TT_INTERPRETER_VERSION_38;
- error = FT_Property_Set(library, "truetype", "interpreter-version", &interpreter_version);
- if (error) std::cout << "Property setting failed!" << std::endl;
- FT_Library_SetLcdFilter(library, FT_LCD_FILTER_DEFAULT);
- if (error) std::cout << "Failed to set LCD filter!" << std::endl;
- FT_Face face;
- error = FT_New_Face(library, "NotoSans-Regular.ttf", 0, &face);
- if (error) std::cout << "Font loading failed!" << std::endl;
- error = FT_Set_Pixel_Sizes(face, 0, 32);
- if (error) std::cout << "Failed to change font size!" << std::endl;
- FT_UInt glyph_index = FT_Get_Char_Index(face, 'T');
- error = FT_Load_Glyph(face, glyph_index, FT_LOAD_TARGET_LCD);
- if (error) std::cout << "Glyph load failed!" << std::endl;
- error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_LCD);
- if (error) std::cout << "Glyph render failed!" << std::endl;
- // Bitmap exporting
- FT_Bitmap *result = &face->glyph->bitmap;
- char *pixelData = new char[result->width * result->rows];
- for (int i = 0; i < result->width / 3 * result->rows; i++) {
- // Reversing channel order
- pixelData[i * 3 ] = result->buffer[i * 3 + 2];
- pixelData[i * 3 + 1] = result->buffer[i * 3 + 1];
- pixelData[i * 3 + 2] = result->buffer[i * 3];
- }
- FileUtility::createBitmapFile("out.bmp", result->width / 3, result->rows, pixelData);
- delete[] pixelData;
- FT_Done_Face(face);
- FT_Done_FreeType(library);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement