Add more testing load buffers

This commit is contained in:
Krzosa Karol
2024-07-21 11:07:32 +02:00
parent 816c24c1b6
commit 846d4e7ab5
4 changed files with 147 additions and 50 deletions

View File

@@ -1,15 +1,20 @@
void LoadBigText(Buffer *buffer) {
for (int i = 0; i < 5000000; i += 1) {
void LoadBigText(Buffer *buffer, int size = 5000000) {
for (int i = 0; i < size; i += 1) {
ReplaceText(buffer, GetEndAsRange(*buffer), L"Line number and another meme or something of the sort which is here or there frankly somewhere\n");
}
}
void LoadBigLine(Buffer *buffer) {
for (int i = 0; i < 5000000; i += 1) {
void LoadBigLine(Buffer *buffer, int size = 5000000) {
for (int i = 0; i < size; i += 1) {
ReplaceText(buffer, GetEndAsRange(*buffer), L"Line number and another meme or something of the sort which is here or there frankly somewhere");
}
}
void LoadBigTextAndBigLine(Buffer *buffer, int size = 2500000) {
LoadBigLine(buffer, size);
LoadBigText(buffer, size);
}
void LoadTextA(Buffer *buffer) {
Scratch scratch;
for (int i = 0; i < 1000; i += 1) {
@@ -23,4 +28,130 @@ void LoadLine(Buffer *buffer) {
Scratch scratch;
String s = "Line number and so on óźćż";
ReplaceText(buffer, {}, ToString16(scratch, s));
}
void LoadUnicode(Buffer *buffer) {
String text = R"===(
This page contains characters from each of the Unicode character blocks.
See also Unicode 3.2 test page.
Basic Latin
! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
Latin-1 Supplement
¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ
Latin Extended-A
Ā ā Ă ă Ą ą Ć ć Ĉ ĉ Ċ ċ Č č Ď ď Đ đ Ē ē Ĕ ĕ Ė ė Ę ę Ě ě Ĝ ĝ Ğ ğ Ġ ġ Ģ ģ Ĥ ĥ Ħ ħ Ĩ ĩ Ī ī Ĭ ĭ Į į İ ı IJ ij Ĵ ĵ Ķ ķ ĸ Ĺ ĺ Ļ ļ Ľ ľ Ŀ ŀ Ł ł Ń ń Ņ ņ Ň ň ʼn Ŋ ŋ Ō ō Ŏ ŏ Ő ő Œ œ Ŕ ŕ Ŗ ŗ Ř ř Ś ś Ŝ ŝ Ş ş Š š Ţ ţ Ť ť Ŧ ŧ Ũ ũ Ū ū Ŭ ŭ Ů ů Ű ű Ų ų Ŵ ŵ Ŷ ŷ Ÿ Ź ź Ż ż Ž ž ſ
Latin Extended-B
ƀ Ɓ Ƃ ƃ Ƅ ƅ Ɔ Ƈ ƈ Ɖ Ɗ Ƌ ƌ ƍ Ǝ Ə Ɛ Ƒ ƒ Ɠ Ɣ ƕ Ɩ Ɨ Ƙ ƙ ƚ ƛ Ɯ Ɲ ƞ Ɵ Ơ ơ Ƣ ƣ Ƥ ƥ Ʀ Ƨ ƨ Ʃ ƪ ƫ Ƭ ƭ Ʈ Ư ư Ʊ Ʋ Ƴ ƴ Ƶ ƶ Ʒ Ƹ ƹ ƺ ƻ Ƽ ƽ ƾ ƿ ǀ ǁ ǂ ǃ DŽ Dž dž LJ Lj lj NJ Nj nj Ǎ ǎ Ǐ ǐ Ǒ ǒ Ǔ ǔ Ǖ ǖ Ǘ ǘ Ǚ ǚ Ǜ ǜ ǝ Ǟ ǟ Ǡ ǡ Ǣ ǣ Ǥ ǥ Ǧ ǧ Ǩ ǩ Ǫ ǫ Ǭ ǭ Ǯ ǯ ǰ DZ Dz dz Ǵ ǵ Ǻ ǻ Ǽ ǽ Ǿ ǿ Ȁ ȁ Ȃ ȃ ...
IPA Extensions
ɐ ɑ ɒ ɓ ɔ ɕ ɖ ɗ ɘ ə ɚ ɛ ɜ ɝ ɞ ɟ ɠ ɡ ɢ ɣ ɤ ɥ ɦ ɧ ɨ ɩ ɪ ɫ ɬ ɭ ɮ ɯ ɰ ɱ ɲ ɳ ɴ ɵ ɶ ɷ ɸ ɹ ɺ ɻ ɼ ɽ ɾ ɿ ʀ ʁ ʂ ʃ ʄ ʅ ʆ ʇ ʈ ʉ ʊ ʋ ʌ ʍ ʎ ʏ ʐ ʑ ʒ ʓ ʔ ʕ ʖ ʗ ʘ ʙ ʚ ʛ ʜ ʝ ʞ ʟ ʠ ʡ ʢ ʣ ʤ ʥ ʦ ʧ ʨ
Spacing Modifier Letters
ʰ ʱ ʲ ʳ ʴ ʵ ʶ ʷ ʸ ʹ ʺ ʻ ʼ ʽ ʾ ʿ ˀ ˁ ˂ ˃ ˄ ˅ ˆ ˇ ˈ ˉ ˊ ˋ ˌ ˍ ˎ ˏ ː ˑ ˒ ˓ ˔ ˕ ˖ ˗ ˘ ˙ ˚ ˛ ˜ ˝ ˞ ˠ ˡ ˢ ˣ ˤ ˥ ˦ ˧ ˨ ˩
Combining Diacritical Marks
̀ ́ ̂ ̃ ̄ ̅ ̆ ̇ ̈ ̉ ̊ ̋ ̌ ̍ ̎ ̏ ̐ ̑ ̒ ̓ ̔ ̕ ̖ ̗ ̘ ̙ ̚ ̛ ̜ ̝ ̞ ̟ ̠ ̡ ̢ ̣ ̤ ̥ ̦ ̧ ̨ ̩ ̪ ̫ ̬ ̭ ̮ ̯ ̰ ̱ ̲ ̳ ̴ ̵ ̶ ̷ ̸ ̹ ̺ ̻ ̼ ̽ ̾ ̿ ̀ ́ ͂ ̓ ̈́ ͅ ͠ ͡
Greek
ʹ ͵ ͺ ; ΄ ΅ Ά · Έ Ή Ί Ό Ύ Ώ ΐ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω Ϊ Ϋ ά έ ή ί ΰ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ ς σ τ υ φ χ ψ ω ϊ ϋ ό ύ ώ ϐ ϑ ϒ ϓ ϔ ϕ ϖ Ϛ Ϝ Ϟ Ϡ Ϣ ϣ Ϥ ϥ Ϧ ϧ Ϩ ϩ Ϫ ϫ Ϭ ϭ Ϯ ϯ ϰ ϱ ϲ ϳ
Cyrillic
Ё Ђ Ѓ Є Ѕ І Ї Ј Љ Њ Ћ Ќ Ў Џ А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я а б в г д е ж з и й к л м н о п р с т у ф х ц ч ш щ ъ ы ь э ю я ё ђ ѓ є ѕ і ї ј љ њ ћ ќ ў џ Ѡ ѡ Ѣ ѣ Ѥ ѥ Ѧ ѧ Ѩ ѩ Ѫ ѫ Ѭ ѭ Ѯ ѯ Ѱ ѱ Ѳ ѳ Ѵ ѵ Ѷ ѷ Ѹ ѹ Ѻ ѻ Ѽ ѽ Ѿ ѿ Ҁ ҁ ҂ ҃ ...
Armenian
Ա Բ Գ Դ Ե Զ Է Ը Թ Ժ Ի Լ Խ Ծ Կ Հ Ձ Ղ Ճ Մ Յ Ն Շ Ո Չ Պ Ջ Ռ Ս Վ Տ Ր Ց Ւ Փ Ք Օ Ֆ ՙ ՚ ՛ ՜ ՝ ՞ ՟ ա բ գ դ ե զ է ը թ ժ ի լ խ ծ կ հ ձ ղ ճ մ յ ն շ ո չ պ ջ ռ ս վ տ ր ց ւ փ ք օ ֆ և ։
Hebrew
֑ ֒ ֓ ֔ ֕ ֖ ֗ ֘ ֙ ֚ ֛ ֜ ֝ ֞ ֟ ֠ ֡ ֣ ֤ ֥ ֦ ֧ ֨ ֩ ֪ ֫ ֬ ֭ ֮ ֯ ְ ֱ ֲ ֳ ִ ֵ ֶ ַ ָ ֹ ֻ ּ ֽ ־ ֿ ׀ ׁ ׂ ׃ ׄ א ב ג ד ה ו ז ח ט י ך כ ל ם מ ן נ ס ע ף פ ץ צ ק ר ש ת װ ױ ײ ׳ ״
Arabic
، ؛ ؟ ء آ أ ؤ إ ئ ا ب ة ت ث ج ح خ د ذ ر ز س ش ص ض ط ظ ع غ ـ ف ق ك ل م ن ه و ى ي ً ٌ ٍ َ ُ ِ ّ ْ ٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩ ٪ ٫ ٬ ٭ ٰ ٱ ٲ ٳ ٴ ٵ ٶ ٷ ٸ ٹ ٺ ٻ ټ ٽ پ ٿ ڀ ځ ڂ ڃ ڄ څ چ ڇ ڈ ډ ڊ ڋ ڌ ڍ ڎ ڏ ڐ ڑ ڒ ړ ڔ ڕ ږ ڗ ژ ڙ ښ ڛ ڜ ڝ ڞ ڟ ڠ ڡ ڢ ڣ ڤ ڥ ڦ ڧ ڨ ک ڪ ګ ڬ ڭ ڮ گ ڰ ڱ ...
Devanagari
ि
Bengali
ি
Gurmukhi
ਿ
Gujarati
િ
Oriya
ି
Tamil
ி
Telugu
ి
Kannada
ಿ
Malayalam
ി
Thai
฿
Lao
Tibetan
༿ ཿ ...
Georgian
Hangul Jamo
...
Latin Extended Additional
ḿ ṿ ...
Greek Extended
Ἷ ...
General Punctuation
 
Superscripts and Subscripts
Currency Symbols
Combining Marks for Symbols
Letterlike Symbols
Number Forms
Arrows
Mathematical Operators
...
Miscellaneous Technical
Control Pictures
Optical Character Recognition
Enclosed Alphanumerics
...
Box Drawing
Block Elements
Geometric Shapes
Miscellaneous Symbols
Dingbats
...
CJK Symbols and Punctuation
 
Hiragana
Katakana
Bopomofo
)===";
Scratch scratch;
ReplaceText(buffer, {}, ToString16(scratch, text));
text = R"===(
Hangul Compatibility Jamo
Kanbun
Enclosed CJK Letters and Months
...
CJK Compatibility
...
CJK Unified Ideographs
丿 乿 ...
Hangul Syllables
갿 걿 ...)===";
ReplaceText(buffer, GetEndAsRange(*buffer), ToString16(scratch, text));
}

View File

@@ -14,12 +14,10 @@ Rect2I GetScreenRect() {
}
Int GetCharSpacing(Font font, Int font_size, Int spacing) {
int index = GetGlyphIndex(font, '_');
int index = GetGlyphIndex(font, '_');
Int textOffsetX = 0;
Int scaleFactor = font_size / font.baseSize; // Character quad scaling factor
if (font.glyphs[index].advanceX == 0) textOffsetX += ((Int)font.recs[index].width * scaleFactor + spacing);
else textOffsetX += ((Int)font.glyphs[index].advanceX * scaleFactor + spacing);
if (font.glyphs[index].advanceX == 0) textOffsetX += ((Int)font.recs[index].width + spacing);
else textOffsetX += ((Int)font.glyphs[index].advanceX + spacing);
return textOffsetX;
}
@@ -27,9 +25,6 @@ void DrawString(Font font, String16 text, Vector2 position, float fontSize, floa
if (font.texture.id == 0) font = GetFontDefault(); // Security check in case of not valid font
float textOffsetX = 0.0f; // Offset X to next character to draw
float scaleFactor = fontSize / font.baseSize; // Character quad scaling factor
for (Int i = 0; i < text.len; i += 1) {
// Get next codepoint from byte string and glyph index in font
int codepoint = text[i];
@@ -41,36 +36,7 @@ void DrawString(Font font, String16 text, Vector2 position, float fontSize, floa
DrawTextCodepoint(font, codepoint, {position.x + textOffsetX, position.y}, fontSize, tint);
}
if (font.glyphs[index].advanceX == 0) textOffsetX += ((float)font.recs[index].width * scaleFactor + spacing);
else textOffsetX += ((float)font.glyphs[index].advanceX * scaleFactor + spacing);
if (font.glyphs[index].advanceX == 0) textOffsetX += ((float)font.recs[index].width + spacing);
else textOffsetX += ((float)font.glyphs[index].advanceX + spacing);
}
}
Vector2 MeasureString(Font font, String16 text, float fontSize, float spacing) {
Vector2 textSize = {0};
if ((font.texture.id == 0) || (text.data == NULL)) return textSize; // Security check
int size = (int)text.len; // Get size in bytes of text
int tempByteCounter = 0; // Used to count longer text line num chars
int byteCounter = 0;
float textWidth = 0.0f;
float tempTextWidth = 0.0f; // Used to count longer text line width
float textHeight = fontSize;
float scaleFactor = fontSize / (float)font.baseSize;
for (int i = 0; i < size; i += 1) {
int index = GetGlyphIndex(font, text[i]);
if (font.glyphs[index].advanceX != 0) textWidth += font.glyphs[index].advanceX;
else textWidth += (font.recs[index].width + font.glyphs[index].offsetX);
}
if (tempTextWidth < textWidth) tempTextWidth = textWidth;
textSize.x = tempTextWidth * scaleFactor + (float)((tempByteCounter - 1) * spacing);
textSize.y = textHeight;
return textSize;
}

View File

@@ -65,7 +65,7 @@ int main(void) {
View view = {};
{
Int font_size = 32;
Int font_size = 16;
Int font_spacing = 1;
Int line_spacing = font_size;
Font font = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)font_size, NULL, 500);
@@ -77,9 +77,12 @@ int main(void) {
view.char_spacing = GetCharSpacing(font, font_size, font_spacing);
Add(&view.carets, {0, 0});
view.buffer = CreateBuffer(Perm);
LoadUnicode(view.buffer);
// LoadBigTextAndBigLine(view.buffer);
// LoadBigLine(view.buffer);
// LoadBigText(view.buffer);
// LoadTextA(view.buffer);
LoadLine(view.buffer);
// LoadLine(view.buffer);
}
while (!WindowShouldClose()) {

View File

@@ -26,14 +26,11 @@ void DrawVisibleCells(const View &view) {
for (Int line_index = visible.min.y; line_index < visible.max.y && line_index >= 0 && line_index < view.buffer->line_starts.len; line_index += 1) {
Range line_range = GetLineRange(*view.buffer, line_index);
String16 line_string = GetString(*view.buffer, line_range);
line_string = Skip(line_string, visible.min.x);
line_string = GetPrefix(line_string, visible.max.x - visible.min.x);
Vec2I pos = {visible.min.x * (Int)view.char_spacing, line_index * (Int)view.line_spacing};
pos -= view.scroll;
float text_offset_x = 0;
float scale_factor = (float)view.font_size / view.font.baseSize; // Character quad scaling factor
for (Int col_index = visible.min.x; col_index < visible.max.x && col_index >= 0 && col_index < line_string.len; col_index += 1) {
int codepoint = line_string[col_index];
int index = GetGlyphIndex(view.font, codepoint);
@@ -44,8 +41,8 @@ void DrawVisibleCells(const View &view) {
DrawTextCodepoint(view.font, codepoint, {(float)pos.x + text_offset_x, (float)pos.y}, (float)view.font_size, tint);
}
if (view.font.glyphs[index].advanceX == 0) text_offset_x += ((float)view.font.recs[index].width * scale_factor + view.font_spacing);
else text_offset_x += ((float)view.font.glyphs[index].advanceX * scale_factor + view.font_spacing);
if (view.font.glyphs[index].advanceX == 0) text_offset_x += ((float)view.font.recs[index].width + view.font_spacing);
else text_offset_x += ((float)view.font.glyphs[index].advanceX + view.font_spacing);
}
}
}