PolyFont.cpp 968 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * PolyFont.cpp
  3. * TAU
  4. *
  5. * Created by Ivan Safrin on 3/16/08.
  6. * Copyright 2008 __MyCompanyName__. All rights reserved.
  7. *
  8. */
  9. #include "PolyFont.h"
  10. using namespace Polycode;
  11. Font::Font(String fileName) {
  12. FT_Library FTLibrary;
  13. FT_Init_FreeType(&FTLibrary);
  14. OSFILE *file = OSBasics::open(fileName, "rb");
  15. OSBasics::seek(file, 0, SEEK_END);
  16. long progsize = OSBasics::tell(file);
  17. OSBasics::seek(file, 0, SEEK_SET);
  18. buffer = (unsigned char*)malloc(progsize);
  19. memset(buffer, 0, progsize);
  20. OSBasics::read(buffer, progsize, 1, file);
  21. valid = true;
  22. if(FT_New_Memory_Face(FTLibrary, buffer, progsize, 0, &ftFace) != 0) {
  23. Logger::log("Error loading font %s\n", fileName.c_str());
  24. valid = false;
  25. }
  26. FT_Select_Charmap(ftFace, FT_ENCODING_UNICODE);
  27. //FT_New_Face(FTLibrary, fileName.c_str(), 0, &ftFace);
  28. // free(buffer);
  29. }
  30. bool Font::isValid() {
  31. return valid;
  32. }
  33. Font::~Font() {
  34. free(buffer);
  35. }
  36. FT_Face Font::getFace() {
  37. return ftFace;
  38. }