Janilabo

Untitled

Jul 12th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.03 KB | None | 0 0
  1. function CreateNewFontSet(var MM: TMemoryManagement): Integer;
  2. begin
  3.   Result := (High(MM.font_set) + 1);
  4.   SetLength(MM.font_set, (Result + 1));
  5. end;
  6.  
  7. function AddFontToSet(var MM: TMemoryManagement; font_set_ID: Integer; p_s, n_s: string): Boolean;
  8. var
  9.   h: Integer;
  10. begin
  11.   h := High(MM.font_set);
  12.   if (not InRange(font_set_ID, 0, hh) or not DirectoryExists(p_s + n_s + '\')) then
  13.     Exit;
  14.   h := High(MM.font_set[font_set_ID].chars);
  15.   SetLength(MM.font_set[font_set_ID].chars, (h + 2));
  16.   MM.font_set[font_set_ID].font[(h + 1)].path := p_s;
  17.   MM.font_set[font_set_ID].font[(h + 1)].name := n_s;
  18.   Result := True;
  19. end;
  20.  
  21. function LoadFontFromSetToMemory(var MM: TMemoryManagement; font_set_ID, font_ID: Integer): Boolean;
  22. var
  23.   d: string;
  24. begin
  25.   if (InRange(font_set_ID, 0, High(MM.font_set)) and InRange(font_ID, 0, High(MM.font_set[font_set_ID].font))) then
  26.     if not MM.DTM_set[font_set_ID].font[font_ID].loaded then
  27.     try                                                  
  28.       d := (MM.font_set[font_set_ID].font[font_ID].path + MM.font_set[font_set_ID].font[font_ID].name + '\');
  29.       if not DirectoryExists(d) then
  30.         Exit;  
  31.       MM.font_set[font_set_ID].font[font_ID].chars := LoadChars2();
  32.       MM.font_set[font_set_ID].DTM[DTM_ID].loaded := True;
  33.       Result := True;
  34.     except
  35.       try
  36.         FreeChars2(MM.font_set[font_set_ID].font[font_ID].chars);
  37.       except
  38.       end;
  39.       MM.font_set[font_set_ID].DTM[DTM_ID].loaded := False;
  40.       Result := False;
  41.     end;
  42. end;
  43.  
  44. function FreeFontFromMemoryBySet(var MM: TMemoryManagement; font_set_ID, font_ID: Integer): Boolean;
  45. begin
  46.   if (InRange(font_set_ID, 0, High(MM.font_set)) and InRange(font_ID, 0, High(MM.font_set[font_set_ID].font))) then
  47.     if MM.font_set[font_set_ID].font[font_ID].loaded then
  48.     try
  49.       FreeChars2(MM.font_set[font_set_ID].font[font_ID].chars);
  50.       MM.font_set[font_set_ID].font[font_ID].loaded := False;
  51.       Result := True;
  52.     except
  53.       MM.font_set[font_set_ID].font[font_ID].loaded := True;
  54.       Result := False;
  55.     end;
  56. end;
  57.  
  58. function FreefontsFromMemoryBySet(var MM: TMemoryManagement; font_set_ID: Integer): Boolean;
  59. var
  60.   h, i, e: Integer;
  61. begin
  62.   if InRange(font_set_ID, 0, High(MM.font_set)) then
  63.   begin
  64.     h := High(MM.font_set[font_set_ID].font);
  65.     Result := (h > -1);
  66.     for i := 0 to h do
  67.     try
  68.       if MM.font_set[font_set_ID].font[i].loaded then
  69.       begin
  70.         FreeChars2(MM.font_set[font_set_ID].font[i].chars);
  71.         MM.font_set[font_set_ID].font[i].loaded := False;
  72.       end;
  73.     except
  74.       Inc(e);
  75.       WriteLn('WARNING[' + IntToStr(e) + ']: Failed to free font "' + MM.font_set[font_set_ID].font[i].name + '" (font_set[' + IntToStr(font_set_ID) + '] - font[' + IntToStr(i) + '])!');
  76.       MM.font_set[font_set_ID].font[i].loaded := True;
  77.       Result := False;
  78.     end;
  79.   end;
  80. end;
  81.  
  82. procedure FreeFontsFromMemory(var MM: TMemoryManagement);
  83. var
  84.   h, i: Integer;
  85. begin
  86.   h := High(MM.font_set);
  87.   for i := 0 to h do
  88.     FreeFontsFromMemoryBySet(MM, i);
  89. end;
Advertisement
Add Comment
Please, Sign In to add comment