diff options
Diffstat (limited to 'cd/src/cd_util.c')
-rwxr-xr-x | cd/src/cd_util.c | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/cd/src/cd_util.c b/cd/src/cd_util.c index 1767ac4..20e9a46 100755 --- a/cd/src/cd_util.c +++ b/cd/src/cd_util.c @@ -263,6 +263,29 @@ void cdRotatePoint(cdCanvas* canvas, int x, int y, int cx, int cy, int *rx, int *ry = *ry + cy; } +void cdfRotatePoint(cdCanvas* canvas, double x, double y, double cx, double cy, double *rx, double *ry, double sin_theta, double cos_theta) +{ + /* translate to (cx,cy) */ + x = x - cx; + y = y - cy; + + /* rotate */ + if (canvas->invert_yaxis) + { + *rx = (x * cos_theta) + (y * sin_theta); + *ry = -(x * sin_theta) + (y * cos_theta); + } + else + { + *rx = (x * cos_theta) - (y * sin_theta); + *ry = (x * sin_theta) + (y * cos_theta); + } + + /* translate back */ + *rx = *rx + cx; + *ry = *ry + cy; +} + void cdRotatePointY(cdCanvas* canvas, int x, int y, int cx, int cy, int *ry, double sin_theta, double cos_theta) { double t; @@ -285,6 +308,8 @@ void cdRotatePointY(cdCanvas* canvas, int x, int y, int cx, int cy, int *ry, dou *ry = *ry + cy; } +/* Copied from IUP3 */ + int cdStrEqualNoCase(const char* str1, const char* str2) { int i = 0; @@ -298,6 +323,20 @@ int cdStrEqualNoCase(const char* str1, const char* str2) return 0; } +int cdStrEqualNoCasePartial(const char* str1, const char* str2) +{ + int i = 0; + if (str1 == str2) return 1; + if (!str1 || !str2 || tolower(*str1) != tolower(*str2)) return 0; + + while (str1[i] && str2[i] && tolower(str1[i])==tolower(str2[i])) + i++; + if (str1[i] == str2[i]) return 1; + if (str2[i] == 0) return 1; + + return 0; +} + /* Copied from IUP3, simply ignore line breaks other than '\n' for CD */ int cdStrLineCount(const char* str) @@ -349,3 +388,108 @@ char* cdStrDupN(const char *str, int len) } return NULL; } + +void cdSetPaperSize(int size, double *w_pt, double *h_pt) +{ + static struct + { + int w_pt; + int h_pt; + } paper[] = + { + { 2393, 3391 }, /* A0 */ + { 1689, 2393 }, /* A1 */ + { 1192, 1689 }, /* A2 */ + { 842, 1192 }, /* A3 */ + { 595, 842 }, /* A4 */ + { 420, 595 }, /* A5 */ + { 612, 792 }, /* LETTER */ + { 612, 1008 } /* LEGAL */ + }; + + if (size<CD_A0 || size>CD_LEGAL) + return; + + *w_pt = (double)paper[size].w_pt; + *h_pt = (double)paper[size].h_pt; +} + +#ifdef WIN32 +#include <windows.h> +static int sReadStringKey(HKEY base_key, char* key_name, char* value_name, char* value) +{ + HKEY key; + DWORD max_size = 512; + + if (RegOpenKeyEx(base_key, key_name, 0, KEY_READ, &key) != ERROR_SUCCESS) + return 0; + + if (RegQueryValueEx(key, value_name, NULL, NULL, (LPBYTE)value, &max_size) != ERROR_SUCCESS) + { + RegCloseKey(key); + return 0; + } + + RegCloseKey(key); + return 1; +} + +static char* sGetFontDir(void) +{ + static char font_dir[512]; + if (!sReadStringKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Fonts", font_dir)) + return ""; + else + { + int i, size = (int)strlen(font_dir); + for(i = 0; i < size; i++) + { + if (font_dir[i] == '\\') + font_dir[i] = '/'; + } + return font_dir; + } +} +#endif + +int cdGetFontFileName(const char* font, char* filename) +{ + FILE *file; + + /* current directory */ + sprintf(filename, "%s.ttf", font); + file = fopen(filename, "r"); + + if (file) + fclose(file); + else + { + /* CD environment */ + char* env = getenv("CDDIR"); + if (env) + { + sprintf(filename, "%s/%s.ttf", env, font); + file = fopen(filename, "r"); + } + + if (file) + fclose(file); + else + { +#ifdef WIN32 + /* Windows Font folder */ + sprintf(filename, "%s/%s.ttf", sGetFontDir(), font); + file = fopen(filename, "r"); + + if (file) + fclose(file); + else + return 0; +#else + return 0; +#endif + } + } + + return 1; +} |