Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/font.c
| Show All 31 Lines | |||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include <math.h> | #include <math.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <wchar.h> | #include <wchar.h> | ||||
| #include <wctype.h> | #include <wctype.h> | ||||
| #include "CLG_log.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_ghash.h" | #include "BLI_ghash.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_string_utf8.h" | #include "BLI_string_utf8.h" | ||||
| Show All 9 Lines | |||||
| #include "BKE_packedFile.h" | #include "BKE_packedFile.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_font.h" | #include "BKE_font.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_anim.h" | #include "BKE_anim.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| static CLG_LogRef LOG = {"bke.data_transfer"}; | |||||
| static ThreadRWMutex vfont_rwlock = BLI_RWLOCK_INITIALIZER; | static ThreadRWMutex vfont_rwlock = BLI_RWLOCK_INITIALIZER; | ||||
| /* The vfont code */ | /* The vfont code */ | ||||
| void BKE_vfont_free_data(struct VFont *vfont) | void BKE_vfont_free_data(struct VFont *vfont) | ||||
| { | { | ||||
| if (vfont->data) { | if (vfont->data) { | ||||
| if (vfont->data->characters) { | if (vfont->data->characters) { | ||||
| GHashIterator gh_iter; | GHashIterator gh_iter; | ||||
| ▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| builtin_font_data = mem; | builtin_font_data = mem; | ||||
| builtin_font_size = size; | builtin_font_size = size; | ||||
| } | } | ||||
| static PackedFile *get_builtin_packedfile(void) | static PackedFile *get_builtin_packedfile(void) | ||||
| { | { | ||||
| if (!builtin_font_data) { | if (!builtin_font_data) { | ||||
| printf("Internal error, builtin font not loaded\n"); | CLOG_ERROR(&LOG, "Internal error, builtin font not loaded"); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| else { | else { | ||||
| void *mem = MEM_mallocN(builtin_font_size, "vfd_builtin"); | void *mem = MEM_mallocN(builtin_font_size, "vfd_builtin"); | ||||
| memcpy(mem, builtin_font_data, builtin_font_size); | memcpy(mem, builtin_font_data, builtin_font_size); | ||||
| Show All 38 Lines | else { | ||||
| else { | else { | ||||
| pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id)); | pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id)); | ||||
| if (vfont->temp_pf == NULL) { | if (vfont->temp_pf == NULL) { | ||||
| vfont->temp_pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id)); | vfont->temp_pf = newPackedFile(NULL, vfont->name, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id)); | ||||
| } | } | ||||
| } | } | ||||
| if (!pf) { | if (!pf) { | ||||
| printf("Font file doesn't exist: %s\n", vfont->name); | CLOG_WARN(&LOG, "Font file doesn't exist: %s", vfont->name); | ||||
| /* DON'T DO THIS | /* DON'T DO THIS | ||||
| * missing file shouldn't modify path! - campbell */ | * missing file shouldn't modify path! - campbell */ | ||||
| #if 0 | #if 0 | ||||
| strcpy(vfont->name, FO_BUILTIN_NAME); | strcpy(vfont->name, FO_BUILTIN_NAME); | ||||
| #endif | #endif | ||||
| pf = get_builtin_packedfile(); | pf = get_builtin_packedfile(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 650 Lines • ▼ Show 20 Lines | makebreak: | ||||
| twidth = char_width(cu, che, info); | twidth = char_width(cu, che, info); | ||||
| /* Calculate positions */ | /* Calculate positions */ | ||||
| if ((tb_scale.w != 0.0f) && | if ((tb_scale.w != 0.0f) && | ||||
| (ct->dobreak == 0) && | (ct->dobreak == 0) && | ||||
| (((xof - tb_scale.x) + twidth) > xof_scale + tb_scale.w)) | (((xof - tb_scale.x) + twidth) > xof_scale + tb_scale.w)) | ||||
| { | { | ||||
| // fprintf(stderr, "linewidth exceeded: %c%c%c...\n", mem[i], mem[i+1], mem[i+2]); | // CLOG_WARN(&LOG, "linewidth exceeded: %c%c%c...", mem[i], mem[i+1], mem[i+2]); | ||||
| for (j = i; j && (mem[j] != '\n') && (chartransdata[j].dobreak == 0); j--) { | for (j = i; j && (mem[j] != '\n') && (chartransdata[j].dobreak == 0); j--) { | ||||
| bool dobreak = false; | bool dobreak = false; | ||||
| if (mem[j] == ' ' || mem[j] == '-') { | if (mem[j] == ' ' || mem[j] == '-') { | ||||
| ct -= (i - (j - 1)); | ct -= (i - (j - 1)); | ||||
| cnr -= (i - (j - 1)); | cnr -= (i - (j - 1)); | ||||
| if (mem[j] == ' ') wsnr--; | if (mem[j] == ' ') wsnr--; | ||||
| if (mem[j] == '-') wsnr++; | if (mem[j] == '-') wsnr++; | ||||
| i = j - 1; | i = j - 1; | ||||
| xof = ct->xof; | xof = ct->xof; | ||||
| ct[1].dobreak = 1; | ct[1].dobreak = 1; | ||||
| custrinfo[i + 1].flag |= CU_CHINFO_WRAP; | custrinfo[i + 1].flag |= CU_CHINFO_WRAP; | ||||
| dobreak = true; | dobreak = true; | ||||
| } | } | ||||
| else if (chartransdata[j].dobreak) { | else if (chartransdata[j].dobreak) { | ||||
| // fprintf(stderr, "word too long: %c%c%c...\n", mem[j], mem[j+1], mem[j+2]); | // CLOG_WARN(&LOG, "word too long: %c%c%c...", mem[j], mem[j+1], mem[j+2]); | ||||
| ct->dobreak = 1; | ct->dobreak = 1; | ||||
| custrinfo[i + 1].flag |= CU_CHINFO_WRAP; | custrinfo[i + 1].flag |= CU_CHINFO_WRAP; | ||||
| ct -= 1; | ct -= 1; | ||||
| cnr -= 1; | cnr -= 1; | ||||
| i--; | i--; | ||||
| xof = ct->xof; | xof = ct->xof; | ||||
| dobreak = true; | dobreak = true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 475 Lines • ▼ Show 20 Lines | for (i = 0; i < slen; i++) { | ||||
| break; | break; | ||||
| } | } | ||||
| if (info->flag & CU_CHINFO_SMALLCAPS_CHECK) { | if (info->flag & CU_CHINFO_SMALLCAPS_CHECK) { | ||||
| cha = towupper(cha); | cha = towupper(cha); | ||||
| } | } | ||||
| if (ob == NULL || info->mat_nr > (ob->totcol)) { | if (ob == NULL || info->mat_nr > (ob->totcol)) { | ||||
| /* printf("Error: Illegal material index (%d) in text object, setting to 0\n", info->mat_nr); */ | /* CLOG_ERROR(&LOG, "Illegal material index (%d) in text object, setting to 0", info->mat_nr); */ | ||||
| info->mat_nr = 0; | info->mat_nr = 0; | ||||
| } | } | ||||
| /* We do not want to see any character for \n or \r */ | /* We do not want to see any character for \n or \r */ | ||||
| if (cha != '\n') | if (cha != '\n') | ||||
| buildchar(cu, r_nubase, cha, info, ct->xof, ct->yof, ct->rot, i, font_size); | buildchar(cu, r_nubase, cha, info, ct->xof, ct->yof, ct->rot, i, font_size); | ||||
| if ((info->flag & CU_CHINFO_UNDERLINE) && (cha != '\n')) { | if ((info->flag & CU_CHINFO_UNDERLINE) && (cha != '\n')) { | ||||
| float ulwidth, uloverlap = 0.0f; | float ulwidth, uloverlap = 0.0f; | ||||
| ▲ Show 20 Lines • Show All 302 Lines • Show Last 20 Lines | |||||