18.09.2017, 17:52
(
Last edited by Freaksken; 18/09/2017 at 09:53 PM.
)
This works for ASCII:
Btw, ! is not 15, but space is. ! is 9.
And the widths should be multiplied by the texdraw letter size, not the texdraw width.
EDIT:
Usage for a single character is:
Usage for a string is:
EDIT2:
Keep in mind that the final values depend on TextDrawLetterSize and TextDrawSetOutline.
Also don't forget to set TextDrawSetProportional to 1.
Code:
new const characterWidths[] = {
//Data taken from singleplayer fonts.dat file
0, 15, 15, 15, 15, 15, 15, 15, //NULL is not displayable because it breaks off the string, others display as a space
15, 15, 15, 15, 15, 15, 15, 15, //Display as a space
15, 15, 15, 15, 15, 15, 15, 15, //Display as a space
15, 15, 15, 15, 15, 15, 15, 15, //Display as a space
15, 9, 17, 27, 20, 34, 23, 12, // ! " Ј $ % & '
12, 12, 21, 20, 12, 14, 12, 15, //( ) * + , - . /
23, 15, 21, 21, 21, 21, 21, 21, //0 1 2 3 4 5 6 7
20, 21, 12, 12, 24, 24, 24, 19, //8 9 : ; < = > ?
10, 22, 19, 19, 22, 16, 19, 24, //tmA B C D E F G
22, 11, 16, 21, 15, 28, 24, 27, //H I J K L M N O
20, 25, 19, 19, 18, 23, 23, 31, //P Q R S T U V W
23, 19, 21, 21, 13, 35, 11, 21, //X Y Z ! _
10, 19, 20, 14, 20, 19, 13, 20, //! a b c d e f g
19, 9, 9, 19, 9, 29, 19, 21, //h i j k l m n o
19, 19, 15, 15, 14, 18, 19, 27, //p q r s t u v w
20, 20, 17, 21, 17, 20, 15, 15, //x y z $ [ ]
22, 22, 22, 22, 29, 19, 16, 16, //А Б В Г Ж З И Й
16, 16, 11, 11, 11, 11, 27, 27, //К Л М Н О П Т У
27, 27, 23, 23, 23, 23, 20, 19, //Ф Ц Щ Ъ Ы Ь Я а
19, 19, 19, 30, 14, 19, 19, 19, //б в г ж з и й к
19, 9, 9, 9, 9, 21, 21, 21, //л м н о п т у ф
21, 18, 18, 18, 18, 24, 19, 19, //ц щ ъ ы ь С с ї
20, 18, 19, 19, 21, 19, 19, 19, //0 1 2 3 4 5 6 7
19, 19, 16, 19, 19, 19, 20, 19, //8 9 : A B C D E
16, 19, 19, 9, 19, 20, 14, 29, //F G H I J K L M
19, 19, 19, 19, 19, 19, 21, 19, //N O P Q R S T U
20, 32, 21, 19, 19, 19, 19, 19, //V W X Y Z А Б В
19, 29, 19, 19, 19, 19, 19, 9, //Г Ж З И Й К Л М
9, 9, 9, 19, 19, 19, 19, 19, //Н О П Т У Ф Ц Щ
19, 19, 19, 19, 21, 19, 10, 9 //Ъ Ы Ь Я С ї ' .
};
stock GetCharacterWidth© {
if(c < 0) {
return 0;
}
if(c >= sizeof(characterWidths)) {
return 20; //Default width, also taken from singleplayer fonts.dat file
}
return characterWidths[c];
}
stock GetStringWidth(const string[]) {
new width = 0;
for(new i = 0, size = strlen(string); i < size; i++) {
width += GetCharacterWidth(string[i]);
}
return width;
}
And the widths should be multiplied by the texdraw letter size, not the texdraw width.
EDIT:
Usage for a single character is:
Code:
printf("%d", GetCharacterWidth('a'));
Code:
printf("%d", GetStringWidth("abc"));
Keep in mind that the final values depend on TextDrawLetterSize and TextDrawSetOutline.
Also don't forget to set TextDrawSetProportional to 1.

