From: Koichi KAMICHI Date: Tue, 28 Dec 2004 04:27:31 +0000 (+0000) Subject: Divide combining function of U+2FF4-U+2FFA. X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=20139e1f6cf9bfef0d86ce63e0bafbd6e91937d8;p=chise%2Fkage.git Divide combining function of U+2FF4-U+2FFA. --- diff --git a/kagecgi/kage.h b/kagecgi/kage.h index 9a9dd11..2c5e4f0 100755 --- a/kagecgi/kage.h +++ b/kagecgi/kage.h @@ -1,52 +1,57 @@ -//kage.h -// - -#include "sysdep.h" - -#ifndef _KAGE_H_ -#define _KAGE_H_ - -int kShotai; -#define kMincho 0 -#define kGothic 1 - -#define kMage 10 -#define kRate 20 -#define kResolution (1000 / kRate + 1) * 2 -#define kMinWidthY 2 -#define kMinWidthT 6 -#define kWidth 5 -#define kKakato 3 //has KAKATO = 2, no KAKATO = 1 -#define kKasane 3 -#define kMixdot (kWidth * 2) * (kWidth * 2 - 1) -#define kL2RDfatten 1.1 - -#define kMaxIDSSequenceLength 16 -#define kMaxIDCLength 16 -#define kMaxStrokeDataLength 256 // over 12(digits per integer with +/- flag) * 11(columns) + 1(line end) +//kage.h +// + +#include "sysdep.h" + +#ifndef _KAGE_H_ +#define _KAGE_H_ + +int kShotai; +#define kMincho 0 +#define kGothic 1 + +#define kMage 10 +#define kRate 20 +#define kResolution (1000 / kRate + 1) * 2 +#define kMinWidthY 2 +#define kMinWidthT 6 +#define kWidth 5 +#define kKakato 3 //has KAKATO = 2, no KAKATO = 1 +#define kKasane 3 +#define kMixdot (kWidth * 2) * (kWidth * 2 - 1) +#define kL2RDfatten 1.1 + +#define kMaxIDSSequenceLength 16 +#define kMaxIDCLength 16 +#define kMaxStrokeDataLength 256 // over 12(digits per integer with +/- flag) * 11(columns) + 1(line end) #define FLAG_FLAT_LEFT 1 #define FLAG_FLAT_RIGHT 2 #define FLAG_FLAT_TOP 4 #define FLAG_FLAT_BOTTOM 8 - -typedef struct _kPoint{ - double X; - double Y; -} kPoint; - -kPoint poly[kResolution]; -kPoint poly2[3]; -kPoint poly3[5]; -kPoint poly4[4]; - -//kagedf.c -void dfDrawFont(int, int, int, int, int, int, int, int, int, int, int); -//kagecd.c -void cdDrawBezier(double, double, double, double, double, double, double, double, int, int); -void cdDrawCurve(double, double, double, double, double, double, int, int); -void cdDrawLine(double, double, double, double, int, int); -//kageic.c -void icPolygon(kPoint *, int); - -#endif + +#define FLAG_SURROUND_LEFT 1 +#define FLAG_SURROUND_RIGHT 2 +#define FLAG_SURROUND_TOP 4 +#define FLAG_SURROUND_BOTTOM 8 + +typedef struct _kPoint{ + double X; + double Y; +} kPoint; + +kPoint poly[kResolution]; +kPoint poly2[3]; +kPoint poly3[5]; +kPoint poly4[4]; + +//kagedf.c +void dfDrawFont(int, int, int, int, int, int, int, int, int, int, int); +//kagecd.c +void cdDrawBezier(double, double, double, double, double, double, double, double, int, int); +void cdDrawCurve(double, double, double, double, double, double, int, int); +void cdDrawLine(double, double, double, double, int, int); +//kageic.c +void icPolygon(kPoint *, int); + +#endif diff --git a/kagecgi/kagecgi.h b/kagecgi/kagecgi.h index 26836e6..aec5f0f 100755 --- a/kagecgi/kagecgi.h +++ b/kagecgi/kagecgi.h @@ -1,85 +1,85 @@ -//kagecgi.h -// - -#include "kage.h" -#include "sysdep.h" - -#ifndef _KAGECGI_H_ -#define _KAGECGI_H_ - -// define for localhost environment -#define errorFileSize 3992 -#define errorFileName "error.png" -#define pngFilePath "/var/www/v0.4/" -#define partsdbFileName "/var/www/kagedb/partsdb" -#define idsdbFileName "/var/www/kagedb/idsdb" -#define aliasdbFileName "/var/www/kagedb/aliasdb" - -#define kBaseline 188 -#define pngWidth 200 -#define pngHeight 200 -#define canvasWidth 400 -#define canvasHeight 400 - -#define min(x1,x2) ((x1) > (x2))? (x2):(x1) -#define max(x1,x2) ((x1) > (x2))? (x1):(x2) - -DB *kPartsdbDatabase; -DB *kIdsdbDatabase; -DB *kAliasdbDatabase; - -FILE *debug; - -png_bytepp kageCanvas; - -int kDesign; -int kSize; -int kType; -int kInput; -KGString *kResultText; -int kMode; - -void generateGlyph(const KGString *in, KGString *out); -void searchPartsData(const KGString *in, KGString *out); -void searchAliasData(const KGString *in, KGString *out); -void searchCacheData(const KGString *in, KGString *out); -void doCombine(const KGString *in, KGString *out); -void drawGlyph(const KGString *in, const int mode); - -int isIDS(const KGString *in); -void divideInto2(const KGString *in, KGString *partIDS1, KGString *partIDS3); -void divideInto3(const KGString *in, KGString *partIDS1, KGString *partIDS2, KGString *partIDS3); -void addStrokeWithTransform(const KGString *stroke, const int num, const int *tf, KGString *out, int mode); -void convertArray(int *buf, KGString *out, int size, int mode); -int * convertStroke(const char *in, int *a, int *size); -void convert99(const KGString *in, KGString *out); -void convert99calc(const char *in, KGString *out); - -void DotsWidth(int *dlx, int *drx); -void DotsHeight(int *dly, int *dry); -void PartsWidth(const KGString *in, int *lx, int *rx); -void PartsHeight(const KGString *in, int *ly, int *ry); -KGString * CalcSizes(const KGString *in, int mode); -void DrawBox(); -void CalcOptions(const KGString *in, int *mitsudo, int *flag, double *yoko, double *tate); -void DoDrawParts(const KGString *in, const int lx1, const double rf1, const int ly1, const double rfy1); -void DoDrawMixFont(const KGString *in1, const int lx1, const double rf1, const KGString *in2, const int lx2, const double rf2, const int ly1, const double rfy1, const int ly2, const double rfy2); - -void combineYoko2(const KGString *parts1, const KGString *parts3, int *result); -void combineYoko3(const KGString *parts1, const KGString *parts2, const KGString *parts3, int *result); -void combineTate2(const KGString *parts1, const KGString *parts3, int *result); -void combineTate3(const KGString *parts1, const KGString *parts2, const KGString *parts3, int *result); -void combineHame2(const KGString *parts1, const KGString *parts3, int *result); - -int initDB(); -int closeDB(); -void searchPartsData(const KGString *in, KGString *out); -void searchAliasData(const KGString *in, KGString *out); - -png_bytepp initPng(int width, int height); -int closePng(int width, int height, png_bytepp canvas); -int writePng(int width, int height, png_bytepp image, FILE *fp); - -void fillPolygon(kPoint *p, int number, int col, unsigned char **image); - -#endif +//kagecgi.h +// + +#include "kage.h" +#include "sysdep.h" + +#ifndef _KAGECGI_H_ +#define _KAGECGI_H_ + +// define for localhost environment +#define errorFileSize 3992 +#define errorFileName "error.png" +#define pngFilePath "/var/www/v0.4/" +#define partsdbFileName "/var/www/kagedb/partsdb" +#define idsdbFileName "/var/www/kagedb/idsdb" +#define aliasdbFileName "/var/www/kagedb/aliasdb" + +#define kBaseline 188 +#define pngWidth 200 +#define pngHeight 200 +#define canvasWidth 400 +#define canvasHeight 400 + +#define min(x1,x2) ((x1) > (x2))? (x2):(x1) +#define max(x1,x2) ((x1) > (x2))? (x1):(x2) + +DB *kPartsdbDatabase; +DB *kIdsdbDatabase; +DB *kAliasdbDatabase; + +FILE *debug; + +png_bytepp kageCanvas; + +int kDesign; +int kSize; +int kType; +int kInput; +KGString *kResultText; +int kMode; + +void generateGlyph(const KGString *in, KGString *out); +void searchPartsData(const KGString *in, KGString *out); +void searchAliasData(const KGString *in, KGString *out); +void searchCacheData(const KGString *in, KGString *out); +void doCombine(const KGString *in, KGString *out); +void drawGlyph(const KGString *in, const int mode); + +int isIDS(const KGString *in); +void divideInto2(const KGString *in, KGString *partIDS1, KGString *partIDS3); +void divideInto3(const KGString *in, KGString *partIDS1, KGString *partIDS2, KGString *partIDS3); +void addStrokeWithTransform(const KGString *stroke, const int num, const int *tf, KGString *out, int mode); +void convertArray(int *buf, KGString *out, int size, int mode); +int * convertStroke(const char *in, int *a, int *size); +void convert99(const KGString *in, KGString *out); +void convert99calc(const char *in, KGString *out); + +void DotsWidth(int *dlx, int *drx); +void DotsHeight(int *dly, int *dry); +void PartsWidth(const KGString *in, int *lx, int *rx); +void PartsHeight(const KGString *in, int *ly, int *ry); +KGString * CalcSizes(const KGString *in, int mode); +void DrawBox(); +void CalcOptions(const KGString *in, int *mitsudo, int *flag, double *yoko, double *tate); +void DoDrawParts(const KGString *in, const int lx1, const double rf1, const int ly1, const double rfy1); +void DoDrawMixFont(const KGString *in1, const int lx1, const double rf1, const KGString *in2, const int lx2, const double rf2, const int ly1, const double rfy1, const int ly2, const double rfy2); + +void combineYoko2(const KGString *parts1, const KGString *parts3, int *result); +void combineYoko3(const KGString *parts1, const KGString *parts2, const KGString *parts3, int *result); +void combineTate2(const KGString *parts1, const KGString *parts3, int *result); +void combineTate3(const KGString *parts1, const KGString *parts2, const KGString *parts3, int *result); +void combineHame2(const KGString *parts1, const KGString *parts3, int *result, int surround); + +int initDB(); +int closeDB(); +void searchPartsData(const KGString *in, KGString *out); +void searchAliasData(const KGString *in, KGString *out); + +png_bytepp initPng(int width, int height); +int closePng(int width, int height, png_bytepp canvas); +int writePng(int width, int height, png_bytepp image, FILE *fp); + +void fillPolygon(kPoint *p, int number, int col, unsigned char **image); + +#endif diff --git a/kagecgi/kagecomb.c b/kagecgi/kagecomb.c index 0f4a297..7860322 100755 --- a/kagecgi/kagecomb.c +++ b/kagecgi/kagecomb.c @@ -1,460 +1,483 @@ -//kagecomb.c -// - -#include "kage.h" -#include "kagecgi.h" -#include "sysdep.h" - -void combineYoko2(const KGString *parts1, const KGString *parts3, int *result){ - int f, g, h, i, j, k, l; - int flg_boxL, flg_boxR; - int YsideLa, YsideLb, YsideRa, YsideRb, YheightL, YnanameL, YsmallL; - int pxL, pxR, pyL, pyR; - double prL, prR, pryL, pryR, rL, rR, rTemp; - int lxL, rxL, lxR, rxR; - int dlyL, dryL, dlyR, dryR; - int chk_y1, chk_y2; - int mitsuL, mitsuR; - double yokoL, tateL, yokoR, tateR; - int *buf, strokes; - int tempShotai; - - //initialize - pxL = 0; - pyL = 0; - prL = 1.0; - pryL = 1.0; - pxR = 0; - pyR = 0; - prR = 1.0; - pryR = 1.0; - - YsideLa = 0; - YsideLb = 0; - YsideRa = 0; - YsideRb = 0; - YnanameL = 0; - YheightL = pngWidth * 0.9; - - tempShotai = kShotai; - kShotai = kGothic; - - CalcOptions(parts1, &mitsuL, &flg_boxL, &yokoL, &tateL); - CalcOptions(parts3, &mitsuR, &flg_boxR, &yokoR, &tateR); - - //left parts Y-axis processing #1 - - //if its upper and bottom are flat - if(flg_boxL & FLAG_FLAT_TOP) YsideLa++; - if(flg_boxL & FLAG_FLAT_BOTTOM) YsideLb++; - - //if its goes right-up - j = 0; - buf = convertStroke(parts1->str, buf, &strokes); - for(i = 0; i < strokes; i++){ - if(buf[i * 11 + 0] / 10 == 1){ - j++; - } - } - free(buf); - l = 0; - if(j != 0){ - YsideLb++; - YnanameL++; - } - YheightL = YheightL - (YsideLa + YsideLb) * 2 * kWidth; - - //left parts Y-axis processing #2 - YsmallL = 0; - YsmallL = 1; - if(flg_boxL & FLAG_FLAT_TOP && flg_boxL & FLAG_FLAT_BOTTOM && tateL <= 4){ - YheightL = (double)YheightL * (max(0.65, tateL * 0.22)); - } else if(flg_boxL & FLAG_FLAT_BOTTOM && tateL <= 3){ - YheightL = (double)YheightL * 0.8; - } else if(YnanameL != 0 && flg_boxL & FLAG_FLAT_TOP && tateL <= 4){ - YheightL = (double)YheightL * (max(0.65, tateL * 0.22)); - } else if(YnanameL != 0 && tateL <= 3){ - YheightL = (double)YheightL * 0.8; - } else{ - YsmallL = 0; - } - - //left parts Y-axis processing #3 - DoDrawParts(parts1, pxL, prL, pyL, pryL); - DotsHeight(&dlyL, &dryL); - pryL = (double)YheightL / (dryL - dlyL); - - if(YsmallL != 0){ - if(flg_boxL & FLAG_FLAT_TOP){ - pyL = kBaseline - (double)pngWidth * 0.9 + 6 * kWidth - dlyL * pryL; - } else{ - pyL = kBaseline - (double)pngWidth * 0.9 + 2 * kWidth - dlyL * pryL; - } - } else{ - if(flg_boxL & FLAG_FLAT_BOTTOM || YnanameL != 0){ - pyL = kBaseline - 2 * kWidth - dryL * pryL; - } else{ - pyL = kBaseline - dryL * pryL; - } - } - - //right parts Y-axis processing #1 - if(flg_boxR & FLAG_FLAT_TOP) YsideRa++; - if(flg_boxR & FLAG_FLAT_BOTTOM) YsideRb++; - - DoDrawParts(parts3, pxR, prR, pyR, pryR); - DotsHeight(&dlyR, &dryR); - - pryR = ((double)pngWidth * 0.9 - (YsideRa + YsideRb) * 2 * kWidth) / (dryR - dlyR); - pyR = kBaseline - dryR * pryR; - if(flg_boxR & FLAG_FLAT_BOTTOM){ - pyR = pyR - 2 * kWidth; - } - - //calculate ratio - rL = yokoL; - rR = yokoR; - - if(flg_boxL & FLAG_FLAT_LEFT) rL = rL * 0.7; - if(flg_boxL & FLAG_FLAT_RIGHT) rL = rL * 0.7; - if(flg_boxR & FLAG_FLAT_LEFT) rR = rR * 0.7; - if(flg_boxR & FLAG_FLAT_RIGHT) rR = rR * 0.7; - - rL = pow(rL, 0.6); - rR = pow(rR, 0.6); - - rR = rR * 1.05; - - rTemp = rL + rR; - rL = rL / rTemp; - rR = rR / rTemp; - - prL = rL; - prR = rR; - - //calculate width of each parts #1 - PartsWidth(parts1, &lxL, &rxL); - PartsWidth(parts3, &lxR, &rxR); - g = 0; - - //calculate width of each parts #2 - pxL = 0; - pxR = pngWidth * prL; - - DoDrawMixFont(parts1, pxL, prL, parts3, pxR, prR, pyL, pryL, pyR, pryR); - - //count dots for check crossing over - DotsHeight(&chk_y1, &chk_y2); - k = 0; - for(i = 0; i < pngWidth * 1.1; i++){ - for(j = chk_y1; j <= chk_y2; j++){ - if(kageCanvas[j][i] == 0) k++; - } - } - l = k; - - //get close both parts - h = pxR; - while(k - l < kMixdot && g < kWidth * 2 * kKasane * 2){ - g = g + 2; - f = pxR - g; - DoDrawMixFont(parts1, pxL, prL, parts3, f, prR, pyL, pryL, pyR, pryR); - - //FOR DEBUG - //char fn[256]; - //FILE *fp; - //snprintf(fn,sizeof(fn),"%03d.png",g); - //fp = fopen(fn, "w"); - //writePng(pngWidth, pngHeight, kageCanvas, fp); - //fclose(fp); - - l = 0; - for(i = 0; i < pngWidth * 1.1; i++){ - for(j = chk_y1; j <= chk_y2; j++){ - if(kageCanvas[j][i] == 0) l++; - } - } - } - pxR = f; - - if(flg_boxL & FLAG_FLAT_RIGHT && flg_boxR & FLAG_FLAT_LEFT){ - if(kShotai == kMincho){ - pxR = pxR + kMinWidthT * 2 * kKasane * 3 / 2; - } else { - pxR = pxR + kWidth * 2 * kKasane * 3 / 2; - } - } else { - pxR = pxR + kWidth * 2 * kKasane * 2 / 2; - } - - //set results - result[0] = pxL; - result[1] = pyL; - result[2] = pxL + pngWidth * prL; - result[3] = pyL + pngWidth * pryL; - result[8] = pxR; - result[9] = pyR; - result[10] = pxR + pngWidth * prR; - result[11] = pyR + pngWidth * pryR; - - kShotai = tempShotai; -} - -void combineYoko3(const KGString *parts1, const KGString *parts2, const KGString *parts3, int *result){ - //temp. - KGString *tempString; - int tempResult[8], tempResult2[4]; - int minx, miny, maxx, maxy, width, height, width2, height2; - - tempString = kg_string_new(""); - combineYoko2(parts2, parts3, result); - addStrokeWithTransform(parts2, 1, result, tempString, 1); - addStrokeWithTransform(parts3, 3, result, tempString, 1); - tempResult[0] = result[0]; - tempResult[1] = result[1]; - tempResult[2] = result[2]; - tempResult[3] = result[3]; - tempResult[4] = result[8]; - tempResult[5] = result[9]; - tempResult[6] = result[10]; - tempResult[7] = result[11]; - minx = result[0]; - miny = min(result[1], result[9]); - maxx = result[10]; - maxy = max(result[3], result[11]); - width = maxx - minx; - height = maxy - miny; - - combineYoko2(parts1, tempString, result); - tempResult2[0] = result[8]; - tempResult2[1] = result[9]; - tempResult2[2] = result[10]; - tempResult2[3] = result[11]; - width2 = result[10] - result[8]; - height2 = result[11] - result[9]; - - result[4] = tempResult2[0] + (tempResult[0] - minx) * ((double)width2 / width); // always 0 - result[5] = tempResult2[1] + (tempResult[1] - miny) * ((double)height2 / height); - result[6] = tempResult2[0] + (tempResult[2] - minx) * ((double)width2 / width); - result[7] = tempResult2[1] + (tempResult[3] - miny) * ((double)height2 / height); - result[8] = tempResult2[0] + (tempResult[4] - minx) * ((double)width2 / width); - result[9] = tempResult2[1] + (tempResult[5] - miny) * ((double)height2 / height); - result[10] = tempResult2[0] + (tempResult[6] - minx) * ((double)width2 / width); - result[11] = tempResult2[1] + (tempResult[7] - miny) * ((double)height2 / height); -} - -void combineTate2(const KGString *parts1, const KGString *parts3, int *result){ - int f, g, h, i, j, k, l; - int flg_boxL, flg_boxR; - int pxL, pxR, pyL, pyR; - double prL, prR, pryL, pryR, rL, rR, rTemp; - int lxL, rxL, lxR, rxR; - int lyL, ryL, lyR, ryR; - int dlxL, drxL, dlxR, drxR; - int chk_x1, chk_x2; - int mitsuL, mitsuR; - double yokoL, tateL, yokoR, tateR; - int tempShotai; - - //initialize - pxL = 0; - pyL = 0; - prL = 1.0; - pryL = 1.0; - pxR = 0; - pyR = 0; - prR = 1.0; - pryR = 1.0; - - tempShotai = kShotai; - kShotai = kGothic; - - CalcOptions(parts1, &mitsuL, &flg_boxL, &yokoL, &tateL); - CalcOptions(parts3, &mitsuR, &flg_boxR, &yokoR, &tateR); - - //calculate ratio - rL = tateL; - rR = tateR; - - if(flg_boxL & FLAG_FLAT_TOP) rL = rL * 0.7; - if(flg_boxL & FLAG_FLAT_BOTTOM) rL = rL * 0.7; - if(flg_boxR & FLAG_FLAT_TOP) rR = rR * 0.7; - if(flg_boxR & FLAG_FLAT_BOTTOM) rR = rR * 0.7; - - rL = pow(rL, 0.8); - rR = pow(rR, 0.8); - - rR = rR * 1.1; - - rTemp = rL + rR; - rL = rL / rTemp; - rR = rR / rTemp; - - pryL = rL; - pryR = rR; - - //calucurate size of X-axis - PartsWidth(parts1, &lxL, &rxL); - PartsWidth(parts3, &lxR, &rxR); - PartsHeight(parts1, &lyL, &ryL); - PartsHeight(parts3, &lyR, &ryR); - - //left parts - if(flg_boxL & FLAG_FLAT_LEFT && flg_boxL & FLAG_FLAT_RIGHT){ - prL = min(1.0, (double)yokoL * 0.1 + 0.5) - ((kWidth * 6) / (kSize * 0.9)); - DoDrawParts(parts1, pxL, prL, pyL, pryL); - DotsWidth(&dlxL, &drxL); - pxL = (kSize / 2 - (dlxL + drxL) / 2); - } else if(flg_boxL & FLAG_FLAT_LEFT){ - prL = (kSize * 0.9 - kWidth * 4) / (rxL - lxL); - pxL = kWidth * 4; - } else if(flg_boxL & FLAG_FLAT_RIGHT){ - prL = (kSize * 0.9 - kWidth * 4) / (rxL - lxL); - pxL = (kSize * 0.05 + kWidth * 2) - lxL * prL; - } - - //right parts - if(flg_boxR & FLAG_FLAT_LEFT && flg_boxR & FLAG_FLAT_RIGHT){ - prR = min(1.0, (double)yokoR * 0.1 + 0.5) - ((kWidth * 6) / (kSize * 0.9)); - DoDrawParts(parts3, pxR, prR, pyR, pryR); - DotsWidth(&dlxR, &drxR); - pxR = (kSize / 2 - (dlxR + drxR) / 2); - } else if(flg_boxR & FLAG_FLAT_LEFT){ - prR = (kSize * 0.9 - kWidth * 4) / (rxR - lxR); - pxR = (kSize * 0.05 + kWidth * 3) - lxR * prR; - } else if(flg_boxR & FLAG_FLAT_RIGHT){ - prR = (kSize * 0.9 - kWidth * 4) / (rxR - lxR); - pxR = (kSize * 0.05 + kWidth * 1) - lxR * prR; - } - - g = 0; - - //calculate width of each parts - pyL = kWidth * 1.5 + (kSize - kWidth * 1.5 * 4) * pryL * 0.5 - (lyL + ryL) / 2 * pryL; - pyR = kWidth * 1.5 + (kSize - kWidth * 1.5 * 4) * pryL + kWidth * 1.5 * 2 + (kSize - kWidth * 1.5 * 4) * pryR * 0.5 - (lyR + ryR) / 2 * pryR; - - DoDrawMixFont(parts1, pxL, prL, parts3, pxR, prR, pyL, pryL, pyR, pryR); - - //count dots for check crossing over - DotsWidth(&chk_x1, &chk_x2); - k = 0; - for(i = 0; i < pngWidth * 1.1; i++){ - for(j = chk_x1; j <= chk_x2; j++){ - if(kageCanvas[i][j] == 0) k++; - } - } - l = k; - - //get close both parts - h = pyR; - while(k - l < kMixdot && g < kWidth * (kKasane + 4)){ - g = g + 2; - f = pyR - g; - DoDrawMixFont(parts1, pxL, prL, parts3, pxR, prR, pyL, pryL, f, pryR); - - l = 0; - for(i = 0; i < pngWidth * 1.1; i++){ - for(j = chk_x1; j <= chk_x2; j++){ - if(kageCanvas[i][j] == 0) l++; - } - } - } - pyR = f; - if(k - l > pngWidth * 0.4){ - pyR = pyR + kWidth * 4; - } else { - pyR = pyR + kWidth * 2; - } - - //set results - result[0] = pxL; - result[1] = pyL; - result[2] = pxL + pngWidth * prL; - result[3] = pyL + pngWidth * pryL; - result[8] = pxR; - result[9] = pyR; - result[10] = pxR + pngWidth * prR; - result[11] = pyR + pngWidth * pryR; - - kShotai = tempShotai; -} - -void combineTate3(const KGString *parts1, const KGString *parts2, const KGString *parts3, int *result){ - //temp. - //temp. - KGString *tempString; - int tempResult[8], tempResult2[4]; - int minx, miny, maxx, maxy, width, height, width2, height2; - - tempString = kg_string_new(""); - combineTate2(parts2, parts3, result); - addStrokeWithTransform(parts2, 1, result, tempString, 1); - addStrokeWithTransform(parts3, 3, result, tempString, 1); - tempResult[0] = result[0]; - tempResult[1] = result[1]; - tempResult[2] = result[2]; - tempResult[3] = result[3]; - tempResult[4] = result[8]; - tempResult[5] = result[9]; - tempResult[6] = result[10]; - tempResult[7] = result[11]; - minx = min(result[0], result[8]); - miny = min(result[1], result[9]); - maxx = max(result[2], result[10]); - maxy = max(result[3], result[11]); - width = maxx - minx; - height = maxy - miny; - - combineTate2(parts1, tempString, result); - tempResult2[0] = result[8]; - tempResult2[1] = result[9]; - tempResult2[2] = result[10]; - tempResult2[3] = result[11]; - width2 = result[10] - result[8]; - height2 = result[11] - result[9]; - - result[4] = tempResult2[0] + (tempResult[0] - minx) * ((double)width2 / width); // always 0 - result[5] = tempResult2[1] + (tempResult[1] - miny) * ((double)height2 / height); - result[6] = tempResult2[0] + (tempResult[2] - minx) * ((double)width2 / width); - result[7] = tempResult2[1] + (tempResult[3] - miny) * ((double)height2 / height); - result[8] = tempResult2[0] + (tempResult[4] - minx) * ((double)width2 / width); - result[9] = tempResult2[1] + (tempResult[5] - miny) * ((double)height2 / height); - result[10] = tempResult2[0] + (tempResult[6] - minx) * ((double)width2 / width); - result[11] = tempResult2[1] + (tempResult[7] - miny) * ((double)height2 / height); -} - -void combineHame2(const KGString *parts1, const KGString *parts3, int *result){ - int i, flag; - int *buf, strokes; - double yoko, tate; - int mitsu, flg_box; - - flag = 0; - CalcOptions(parts3, &mitsu, &flg_box, &yoko, &tate); - - //set results - result[0] = 0; - result[1] = 0; - result[2] = 200; - result[3] = 200; - buf = convertStroke(parts1->str, buf, &strokes); - for(i = 0; i < strokes; i++){ - if(buf[i * 11 + 0] == 9){ - result[8] = buf[i * 11 + 3]; - if(flg_box & FLAG_FLAT_LEFT) result[8] += kWidth * 4; - result[9] = buf[i * 11 + 4]; - if(flg_box & FLAG_FLAT_TOP) result[9] += kWidth * 4; - result[10] = buf[i * 11 + 5]; - if(flg_box & FLAG_FLAT_RIGHT) result[10] -= kWidth * 4; - result[11] = buf[i * 11 + 6]; - if(flg_box & FLAG_FLAT_BOTTOM) result[11] -= kWidth * 4; - flag = 1; - } - } - if(flag == 0){ //error - result[8] = 50; - result[9] = 50; - result[10] = 150; - result[11] = 150; - } -} +//kagecomb.c +// + +#include "kage.h" +#include "kagecgi.h" +#include "sysdep.h" + +void combineYoko2(const KGString *parts1, const KGString *parts3, int *result){ + int f, g, h, i, j, k, l; + int flg_boxL, flg_boxR; + int YsideLa, YsideLb, YsideRa, YsideRb, YheightL, YnanameL, YsmallL; + int pxL, pxR, pyL, pyR; + double prL, prR, pryL, pryR, rL, rR, rTemp; + int lxL, rxL, lxR, rxR; + int dlyL, dryL, dlyR, dryR; + int chk_y1, chk_y2; + int mitsuL, mitsuR; + double yokoL, tateL, yokoR, tateR; + int *buf, strokes; + int tempShotai; + + //initialize + pxL = 0; + pyL = 0; + prL = 1.0; + pryL = 1.0; + pxR = 0; + pyR = 0; + prR = 1.0; + pryR = 1.0; + + YsideLa = 0; + YsideLb = 0; + YsideRa = 0; + YsideRb = 0; + YnanameL = 0; + YheightL = pngWidth * 0.9; + + tempShotai = kShotai; + kShotai = kGothic; + + CalcOptions(parts1, &mitsuL, &flg_boxL, &yokoL, &tateL); + CalcOptions(parts3, &mitsuR, &flg_boxR, &yokoR, &tateR); + + //left parts Y-axis processing #1 + + //if its upper and bottom are flat + if(flg_boxL & FLAG_FLAT_TOP) YsideLa++; + if(flg_boxL & FLAG_FLAT_BOTTOM) YsideLb++; + + //if its goes right-up + j = 0; + buf = convertStroke(parts1->str, buf, &strokes); + for(i = 0; i < strokes; i++){ + if(buf[i * 11 + 0] / 10 == 1){ + j++; + } + } + free(buf); + l = 0; + if(j != 0){ + YsideLb++; + YnanameL++; + } + YheightL = YheightL - (YsideLa + YsideLb) * 2 * kWidth; + + //left parts Y-axis processing #2 + YsmallL = 0; + YsmallL = 1; + if(flg_boxL & FLAG_FLAT_TOP && flg_boxL & FLAG_FLAT_BOTTOM && tateL <= 4){ + YheightL = (double)YheightL * (max(0.65, tateL * 0.22)); + } else if(flg_boxL & FLAG_FLAT_BOTTOM && tateL <= 3){ + YheightL = (double)YheightL * 0.8; + } else if(YnanameL != 0 && flg_boxL & FLAG_FLAT_TOP && tateL <= 4){ + YheightL = (double)YheightL * (max(0.65, tateL * 0.22)); + } else if(YnanameL != 0 && tateL <= 3){ + YheightL = (double)YheightL * 0.8; + } else{ + YsmallL = 0; + } + + //left parts Y-axis processing #3 + DoDrawParts(parts1, pxL, prL, pyL, pryL); + DotsHeight(&dlyL, &dryL); + pryL = (double)YheightL / (dryL - dlyL); + + if(YsmallL != 0){ + if(flg_boxL & FLAG_FLAT_TOP){ + pyL = kBaseline - (double)pngWidth * 0.9 + 6 * kWidth - dlyL * pryL; + } else{ + pyL = kBaseline - (double)pngWidth * 0.9 + 2 * kWidth - dlyL * pryL; + } + } else{ + if(flg_boxL & FLAG_FLAT_BOTTOM || YnanameL != 0){ + pyL = kBaseline - 2 * kWidth - dryL * pryL; + } else{ + pyL = kBaseline - dryL * pryL; + } + } + + //right parts Y-axis processing #1 + if(flg_boxR & FLAG_FLAT_TOP) YsideRa++; + if(flg_boxR & FLAG_FLAT_BOTTOM) YsideRb++; + + DoDrawParts(parts3, pxR, prR, pyR, pryR); + DotsHeight(&dlyR, &dryR); + + pryR = ((double)pngWidth * 0.9 - (YsideRa + YsideRb) * 2 * kWidth) / (dryR - dlyR); + pyR = kBaseline - dryR * pryR; + if(flg_boxR & FLAG_FLAT_BOTTOM){ + pyR = pyR - 2 * kWidth; + } + + //calculate ratio + rL = yokoL; + rR = yokoR; + + if(flg_boxL & FLAG_FLAT_LEFT) rL = rL * 0.7; + if(flg_boxL & FLAG_FLAT_RIGHT) rL = rL * 0.7; + if(flg_boxR & FLAG_FLAT_LEFT) rR = rR * 0.7; + if(flg_boxR & FLAG_FLAT_RIGHT) rR = rR * 0.7; + + rL = pow(rL, 0.6); + rR = pow(rR, 0.6); + + rR = rR * 1.05; + + rTemp = rL + rR; + rL = rL / rTemp; + rR = rR / rTemp; + + prL = rL; + prR = rR; + + //calculate width of each parts #1 + PartsWidth(parts1, &lxL, &rxL); + PartsWidth(parts3, &lxR, &rxR); + g = 0; + + //calculate width of each parts #2 + pxL = 0; + pxR = pngWidth * prL; + + DoDrawMixFont(parts1, pxL, prL, parts3, pxR, prR, pyL, pryL, pyR, pryR); + + //count dots for check crossing over + DotsHeight(&chk_y1, &chk_y2); + k = 0; + for(i = 0; i < pngWidth * 1.1; i++){ + for(j = chk_y1; j <= chk_y2; j++){ + if(kageCanvas[j][i] == 0) k++; + } + } + l = k; + + //get close both parts + h = pxR; + while(k - l < kMixdot && g < kWidth * 2 * kKasane * 2){ + g = g + 2; + f = pxR - g; + DoDrawMixFont(parts1, pxL, prL, parts3, f, prR, pyL, pryL, pyR, pryR); + + //FOR DEBUG + //char fn[256]; + //FILE *fp; + //snprintf(fn,sizeof(fn),"%03d.png",g); + //fp = fopen(fn, "w"); + //writePng(pngWidth, pngHeight, kageCanvas, fp); + //fclose(fp); + + l = 0; + for(i = 0; i < pngWidth * 1.1; i++){ + for(j = chk_y1; j <= chk_y2; j++){ + if(kageCanvas[j][i] == 0) l++; + } + } + } + pxR = f; + + if(flg_boxL & FLAG_FLAT_RIGHT && flg_boxR & FLAG_FLAT_LEFT){ + if(kShotai == kMincho){ + pxR = pxR + kMinWidthT * 2 * kKasane * 3 / 2; + } else { + pxR = pxR + kWidth * 2 * kKasane * 3 / 2; + } + } else { + pxR = pxR + kWidth * 2 * kKasane * 2 / 2; + } + + //set results + result[0] = pxL; + result[1] = pyL; + result[2] = pxL + pngWidth * prL; + result[3] = pyL + pngWidth * pryL; + result[8] = pxR; + result[9] = pyR; + result[10] = pxR + pngWidth * prR; + result[11] = pyR + pngWidth * pryR; + + kShotai = tempShotai; +} + +void combineYoko3(const KGString *parts1, const KGString *parts2, const KGString *parts3, int *result){ + //temp. + KGString *tempString; + int tempResult[8], tempResult2[4]; + int minx, miny, maxx, maxy, width, height, width2, height2; + + tempString = kg_string_new(""); + combineYoko2(parts2, parts3, result); + addStrokeWithTransform(parts2, 1, result, tempString, 1); + addStrokeWithTransform(parts3, 3, result, tempString, 1); + tempResult[0] = result[0]; + tempResult[1] = result[1]; + tempResult[2] = result[2]; + tempResult[3] = result[3]; + tempResult[4] = result[8]; + tempResult[5] = result[9]; + tempResult[6] = result[10]; + tempResult[7] = result[11]; + minx = result[0]; + miny = min(result[1], result[9]); + maxx = result[10]; + maxy = max(result[3], result[11]); + width = maxx - minx; + height = maxy - miny; + + combineYoko2(parts1, tempString, result); + tempResult2[0] = result[8]; + tempResult2[1] = result[9]; + tempResult2[2] = result[10]; + tempResult2[3] = result[11]; + width2 = result[10] - result[8]; + height2 = result[11] - result[9]; + + result[4] = tempResult2[0] + (tempResult[0] - minx) * ((double)width2 / width); // always 0 + result[5] = tempResult2[1] + (tempResult[1] - miny) * ((double)height2 / height); + result[6] = tempResult2[0] + (tempResult[2] - minx) * ((double)width2 / width); + result[7] = tempResult2[1] + (tempResult[3] - miny) * ((double)height2 / height); + result[8] = tempResult2[0] + (tempResult[4] - minx) * ((double)width2 / width); + result[9] = tempResult2[1] + (tempResult[5] - miny) * ((double)height2 / height); + result[10] = tempResult2[0] + (tempResult[6] - minx) * ((double)width2 / width); + result[11] = tempResult2[1] + (tempResult[7] - miny) * ((double)height2 / height); +} + +void combineTate2(const KGString *parts1, const KGString *parts3, int *result){ + int f, g, h, i, j, k, l; + int flg_boxL, flg_boxR; + int pxL, pxR, pyL, pyR; + double prL, prR, pryL, pryR, rL, rR, rTemp; + int lxL, rxL, lxR, rxR; + int lyL, ryL, lyR, ryR; + int dlxL, drxL, dlxR, drxR; + int chk_x1, chk_x2; + int mitsuL, mitsuR; + double yokoL, tateL, yokoR, tateR; + int tempShotai; + + //initialize + pxL = 0; + pyL = 0; + prL = 1.0; + pryL = 1.0; + pxR = 0; + pyR = 0; + prR = 1.0; + pryR = 1.0; + + tempShotai = kShotai; + kShotai = kGothic; + + CalcOptions(parts1, &mitsuL, &flg_boxL, &yokoL, &tateL); + CalcOptions(parts3, &mitsuR, &flg_boxR, &yokoR, &tateR); + + //calculate ratio + rL = tateL; + rR = tateR; + + if(flg_boxL & FLAG_FLAT_TOP) rL = rL * 0.7; + if(flg_boxL & FLAG_FLAT_BOTTOM) rL = rL * 0.7; + if(flg_boxR & FLAG_FLAT_TOP) rR = rR * 0.7; + if(flg_boxR & FLAG_FLAT_BOTTOM) rR = rR * 0.7; + + rL = pow(rL, 0.8); + rR = pow(rR, 0.8); + + rR = rR * 1.1; + + rTemp = rL + rR; + rL = rL / rTemp; + rR = rR / rTemp; + + pryL = rL; + pryR = rR; + + //calucurate size of X-axis + PartsWidth(parts1, &lxL, &rxL); + PartsWidth(parts3, &lxR, &rxR); + PartsHeight(parts1, &lyL, &ryL); + PartsHeight(parts3, &lyR, &ryR); + + //left parts + if(flg_boxL & FLAG_FLAT_LEFT && flg_boxL & FLAG_FLAT_RIGHT){ + prL = min(1.0, (double)yokoL * 0.1 + 0.5) - ((kWidth * 6) / (kSize * 0.9)); + DoDrawParts(parts1, pxL, prL, pyL, pryL); + DotsWidth(&dlxL, &drxL); + pxL = (kSize / 2 - (dlxL + drxL) / 2); + } else if(flg_boxL & FLAG_FLAT_LEFT){ + prL = (kSize * 0.9 - kWidth * 4) / (rxL - lxL); + pxL = kWidth * 4; + } else if(flg_boxL & FLAG_FLAT_RIGHT){ + prL = (kSize * 0.9 - kWidth * 4) / (rxL - lxL); + pxL = (kSize * 0.05 + kWidth * 2) - lxL * prL; + } + + //right parts + if(flg_boxR & FLAG_FLAT_LEFT && flg_boxR & FLAG_FLAT_RIGHT){ + prR = min(1.0, (double)yokoR * 0.1 + 0.5) - ((kWidth * 6) / (kSize * 0.9)); + DoDrawParts(parts3, pxR, prR, pyR, pryR); + DotsWidth(&dlxR, &drxR); + pxR = (kSize / 2 - (dlxR + drxR) / 2); + } else if(flg_boxR & FLAG_FLAT_LEFT){ + prR = (kSize * 0.9 - kWidth * 4) / (rxR - lxR); + pxR = (kSize * 0.05 + kWidth * 3) - lxR * prR; + } else if(flg_boxR & FLAG_FLAT_RIGHT){ + prR = (kSize * 0.9 - kWidth * 4) / (rxR - lxR); + pxR = (kSize * 0.05 + kWidth * 1) - lxR * prR; + } + + g = 0; + + //calculate width of each parts + pyL = kWidth * 1.5 + (kSize - kWidth * 1.5 * 4) * pryL * 0.5 - (lyL + ryL) / 2 * pryL; + pyR = kWidth * 1.5 + (kSize - kWidth * 1.5 * 4) * pryL + kWidth * 1.5 * 2 + (kSize - kWidth * 1.5 * 4) * pryR * 0.5 - (lyR + ryR) / 2 * pryR; + + DoDrawMixFont(parts1, pxL, prL, parts3, pxR, prR, pyL, pryL, pyR, pryR); + + //count dots for check crossing over + DotsWidth(&chk_x1, &chk_x2); + k = 0; + for(i = 0; i < pngWidth * 1.1; i++){ + for(j = chk_x1; j <= chk_x2; j++){ + if(kageCanvas[i][j] == 0) k++; + } + } + l = k; + + //get close both parts + h = pyR; + while(k - l < kMixdot && g < kWidth * (kKasane + 4)){ + g = g + 2; + f = pyR - g; + DoDrawMixFont(parts1, pxL, prL, parts3, pxR, prR, pyL, pryL, f, pryR); + + l = 0; + for(i = 0; i < pngWidth * 1.1; i++){ + for(j = chk_x1; j <= chk_x2; j++){ + if(kageCanvas[i][j] == 0) l++; + } + } + } + pyR = f; + if(k - l > pngWidth * 0.4){ + pyR = pyR + kWidth * 4; + } else { + pyR = pyR + kWidth * 2; + } + + //set results + result[0] = pxL; + result[1] = pyL; + result[2] = pxL + pngWidth * prL; + result[3] = pyL + pngWidth * pryL; + result[8] = pxR; + result[9] = pyR; + result[10] = pxR + pngWidth * prR; + result[11] = pyR + pngWidth * pryR; + + kShotai = tempShotai; +} + +void combineTate3(const KGString *parts1, const KGString *parts2, const KGString *parts3, int *result){ + //temp. + KGString *tempString; + int tempResult[8], tempResult2[4]; + int minx, miny, maxx, maxy, width, height, width2, height2; + + tempString = kg_string_new(""); + combineTate2(parts2, parts3, result); + addStrokeWithTransform(parts2, 1, result, tempString, 1); + addStrokeWithTransform(parts3, 3, result, tempString, 1); + tempResult[0] = result[0]; + tempResult[1] = result[1]; + tempResult[2] = result[2]; + tempResult[3] = result[3]; + tempResult[4] = result[8]; + tempResult[5] = result[9]; + tempResult[6] = result[10]; + tempResult[7] = result[11]; + minx = min(result[0], result[8]); + miny = min(result[1], result[9]); + maxx = max(result[2], result[10]); + maxy = max(result[3], result[11]); + width = maxx - minx; + height = maxy - miny; + + combineTate2(parts1, tempString, result); + tempResult2[0] = result[8]; + tempResult2[1] = result[9]; + tempResult2[2] = result[10]; + tempResult2[3] = result[11]; + width2 = result[10] - result[8]; + height2 = result[11] - result[9]; + + result[4] = tempResult2[0] + (tempResult[0] - minx) * ((double)width2 / width); // always 0 + result[5] = tempResult2[1] + (tempResult[1] - miny) * ((double)height2 / height); + result[6] = tempResult2[0] + (tempResult[2] - minx) * ((double)width2 / width); + result[7] = tempResult2[1] + (tempResult[3] - miny) * ((double)height2 / height); + result[8] = tempResult2[0] + (tempResult[4] - minx) * ((double)width2 / width); + result[9] = tempResult2[1] + (tempResult[5] - miny) * ((double)height2 / height); + result[10] = tempResult2[0] + (tempResult[6] - minx) * ((double)width2 / width); + result[11] = tempResult2[1] + (tempResult[7] - miny) * ((double)height2 / height); +} + +void combineHame2(const KGString *parts1, const KGString *parts3, int *result, int surround){ + int i, flag; + int *buf, strokes; + double yoko, tate; + int mitsu, flg_box; + + flag = 0; + CalcOptions(parts3, &mitsu, &flg_box, &yoko, &tate); + + //set results + result[0] = 0; + result[1] = 0; + result[2] = 200; + result[3] = 200; + buf = convertStroke(parts1->str, buf, &strokes); + for(i = 0; i < strokes; i++){ + if(buf[i * 11 + 0] == 9){ + result[8] = buf[i * 11 + 3]; + if(flg_box & FLAG_FLAT_LEFT){ + if(surround & FLAG_SURROUND_LEFT){ + result[8] += kWidth * 4; + } else { + result[8] += kWidth * 2; + } + } + result[9] = buf[i * 11 + 4]; + if(flg_box & FLAG_FLAT_TOP){ + if(surround & FLAG_SURROUND_TOP){ + result[9] += kWidth * 4; + } else { + result[9] += kWidth * 2; + } + } + result[10] = buf[i * 11 + 5]; + if(flg_box & FLAG_FLAT_RIGHT){ + if(surround & FLAG_SURROUND_RIGHT){ + result[10] -= kWidth * 4; + } else { + result[10] -= kWidth * 2; + } + } + result[11] = buf[i * 11 + 6]; + if(flg_box & FLAG_FLAT_BOTTOM){ + if(surround & FLAG_SURROUND_BOTTOM){ + result[11] -= kWidth * 4; + } else { + result[11] -= kWidth * 2; + } + } + flag = 1; + } + } + if(flag == 0){ //error + result[8] = 50; + result[9] = 50; + result[10] = 150; + result[11] = 150; + } +} diff --git a/kagecgi/kageeg.c b/kagecgi/kageeg.c index 891a67c..785047a 100755 --- a/kagecgi/kageeg.c +++ b/kagecgi/kageeg.c @@ -1,242 +1,273 @@ -//kageeg.c -// - -#include "kage.h" -#include "kagecgi.h" -#include "sysdep.h" - -void generateGlyphByIDS(const KGString *in, KGString *out, int flag){ - KGString *tmp1, *tmp2; - - //pass this method if 'in' is not UCS parts - if((in->str)[0] != 'u'){ - generateGlyph(in, out); - return; - } - //pass this method if 'in' is place-variant-flag defined - if(in->len < 5 && 7 < in->len){ - generateGlyph(in, out); - return; - } - - tmp1 = kg_string_new(in->str); - tmp2 = kg_string_new(in->str); - - //append place flag - if(1 <= flag && flag <= 7){ - if(tmp1->len != 7) kg_string_append(tmp1, "-"); - if(flag == 1) kg_string_append(tmp1, "01"); - else if(flag == 2) kg_string_append(tmp1, "02"); - else if(flag == 3) kg_string_append(tmp1, "03"); - else if(flag == 4) kg_string_append(tmp1, "04"); - else if(flag == 5) kg_string_append(tmp1, "05"); - else if(flag == 6) kg_string_append(tmp1, "06"); - } - - generateGlyph(tmp1, out); - if(out->len != 0) return; - generateGlyph(tmp2, out); - if(out->len != 0) return; - return; -} - -void generateGlyph(const KGString *in, KGString *out){ - KGString *tmp; - tmp = kg_string_new(""); - kg_string_set_size(out, 0); - - //search from parts - searchPartsData(in, tmp); - if(tmp->len != 0){ - tmp = CalcSizes(tmp, 1); - out = kg_string_assign(out, tmp->str); - return; - } - - //search from alias - searchAliasData(in, tmp); - if(tmp->len != 0){ - generateGlyph(tmp, out); - if(out->len == 0) return; - //save to cache ... not yet - return; - } - - //check if its IDS - if(isIDS(in)){ - doCombine(in, out); - if(out->len == 0) return; - //save to cache ... not yet - return; - } -} - -void doCombine(const KGString *in, KGString *out){ - KGString *partIDS1, *partIDS2, *partIDS3; - KGString *partStroke1, *partStroke2, *partStroke3; - int result[12]; - - partIDS1 = kg_string_new(""); - partIDS2 = kg_string_new(""); - partIDS3 = kg_string_new(""); - partStroke1 = kg_string_new(""); - partStroke2 = kg_string_new(""); - partStroke3 = kg_string_new(""); - - kg_string_set_size(out, 0); - - //check first IDC - if(strncmp(in->str, "u2ff", 4) != 0) return; - //switch by combine types - switch((in->str)[4]){ - case '0': - divideInto2(in, partIDS1, partIDS3); - if(partIDS1->len == 0) return; - //ready each parts - generateGlyphByIDS(partIDS1, partStroke1, 1); - if(partStroke1->len == 0) return; - partStroke1 = CalcSizes(partStroke1, 0); - generateGlyphByIDS(partIDS3, partStroke3, 2); - if(partStroke3->len == 0) return; - partStroke3 = CalcSizes(partStroke3, 0); - break; - case '1': - divideInto2(in, partIDS1, partIDS3); - if(partIDS1->len == 0) return; - //ready each parts - generateGlyphByIDS(partIDS1, partStroke1, 3); - if(partStroke1->len == 0) return; - partStroke1 = CalcSizes(partStroke1, 0); - generateGlyphByIDS(partIDS3, partStroke3, 4); - if(partStroke3->len == 0) return; - partStroke3 = CalcSizes(partStroke3, 0); - break; - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'a': -// case 'b': - divideInto2(in, partIDS1, partIDS3); - if(partIDS1->len == 0) return; - //ready each parts - generateGlyphByIDS(partIDS1, partStroke1, 5); - if(partStroke1->len == 0) return; - partStroke1 = CalcSizes(partStroke1, 0); - generateGlyphByIDS(partIDS3, partStroke3, 6); - if(partStroke3->len == 0) return; - partStroke3 = CalcSizes(partStroke3, 0); - break; - case '2': - divideInto3(in, partIDS1, partIDS2, partIDS3); - if(partIDS1->len == 0) return; - //ready each parts - generateGlyphByIDS(partIDS1, partStroke1, 1); - if(partStroke1->len == 0) return; - partStroke1 = CalcSizes(partStroke1, 0); - generateGlyphByIDS(partIDS2, partStroke2, 1); - if(partStroke2->len == 0) return; - partStroke2 = CalcSizes(partStroke2, 0); - generateGlyphByIDS(partIDS3, partStroke3, 2); - if(partStroke3->len == 0) return; - partStroke3 = CalcSizes(partStroke3, 0); - break; - case '3': - divideInto3(in, partIDS1, partIDS2, partIDS3); - if(partIDS1->len == 0) return; - //ready each parts - generateGlyphByIDS(partIDS1, partStroke1, 3); - if(partStroke1->len == 0) return; - partStroke1 = CalcSizes(partStroke1, 0); - generateGlyphByIDS(partIDS2, partStroke2, 3); - if(partStroke2->len == 0) return; - partStroke2 = CalcSizes(partStroke2, 0); - generateGlyphByIDS(partIDS3, partStroke3, 4); - if(partStroke3->len == 0) return; - partStroke3 = CalcSizes(partStroke3, 0); - break; - } - switch((in->str)[4]){ - case '0': - combineYoko2(partStroke1, partStroke3, result); - break; - case '1': - combineTate2(partStroke1, partStroke3, result); - break; - case '2': - combineYoko3(partStroke1, partStroke2, partStroke3, result); - break; - case '3': - combineTate3(partStroke1, partStroke2, partStroke3, result); - break; - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'a': -// case 'b': - combineHame2(partStroke1, partStroke3, result); - break; - } - switch((in->str)[4]){ - case '0': - case '1': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'a': -// case 'b': - addStrokeWithTransform(partStroke1, 1, result, out, 1); - addStrokeWithTransform(partStroke3, 3, result, out, 1); - break; - case '2': - case '3': - addStrokeWithTransform(partStroke1, 1, result, out, 1); - addStrokeWithTransform(partStroke2, 2, result, out, 1); - addStrokeWithTransform(partStroke3, 3, result, out, 1); - break; - } -} - -void drawGlyph(const KGString *in, const int mode){ - int i, j; - int *buf; - buf = convertStroke(in->str, buf, &j); - for(i = 0; i < j; i++){ - if(mode == 0){ //normal - dfDrawFont(buf[i * 11 + 0], - buf[i * 11 + 1], - buf[i * 11 + 2], - buf[i * 11 + 3], - buf[i * 11 + 4], - buf[i * 11 + 5], - buf[i * 11 + 6], - buf[i * 11 + 7], - buf[i * 11 + 8], - buf[i * 11 + 9], - buf[i * 11 + 10]); - } - else if(mode == 1){ //without decoration - dfDrawFont(buf[i * 11 + 0], - 0, - 0, - buf[i * 11 + 3], - buf[i * 11 + 4], - buf[i * 11 + 5], - buf[i * 11 + 6], - buf[i * 11 + 7], - buf[i * 11 + 8], - buf[i * 11 + 9], - buf[i * 11 + 10]); - } - } - free(buf); -} - +//kageeg.c +// + +#include "kage.h" +#include "kagecgi.h" +#include "sysdep.h" + +void generateGlyphByIDS(const KGString *in, KGString *out, int flag){ + KGString *tmp1, *tmp2; + + //pass this method if 'in' is not UCS parts + if((in->str)[0] != 'u'){ + generateGlyph(in, out); + return; + } + //pass this method if 'in' is place-variant-flag defined + if(in->len < 5 && 7 < in->len){ + generateGlyph(in, out); + return; + } + + tmp1 = kg_string_new(in->str); + tmp2 = kg_string_new(in->str); + + //append place flag + if(1 <= flag && flag <= 7){ + if(tmp1->len != 7) kg_string_append(tmp1, "-"); + if(flag == 1) kg_string_append(tmp1, "01"); + else if(flag == 2) kg_string_append(tmp1, "02"); + else if(flag == 3) kg_string_append(tmp1, "03"); + else if(flag == 4) kg_string_append(tmp1, "04"); + else if(flag == 5) kg_string_append(tmp1, "05"); + else if(flag == 6) kg_string_append(tmp1, "06"); + } + + generateGlyph(tmp1, out); + if(out->len != 0) return; + generateGlyph(tmp2, out); + if(out->len != 0) return; + return; +} + +void generateGlyph(const KGString *in, KGString *out){ + KGString *tmp; + tmp = kg_string_new(""); + kg_string_set_size(out, 0); + + //search from parts + searchPartsData(in, tmp); + if(tmp->len != 0){ + tmp = CalcSizes(tmp, 1); + out = kg_string_assign(out, tmp->str); + return; + } + + //search from alias + searchAliasData(in, tmp); + if(tmp->len != 0){ + generateGlyph(tmp, out); + if(out->len == 0) return; + //save to cache ... not yet + return; + } + + //check if its IDS + if(isIDS(in)){ + doCombine(in, out); + if(out->len == 0) return; + //save to cache ... not yet + return; + } +} + +void doCombine(const KGString *in, KGString *out){ + KGString *partIDS1, *partIDS2, *partIDS3; + KGString *partStroke1, *partStroke2, *partStroke3; + int result[12]; + + partIDS1 = kg_string_new(""); + partIDS2 = kg_string_new(""); + partIDS3 = kg_string_new(""); + partStroke1 = kg_string_new(""); + partStroke2 = kg_string_new(""); + partStroke3 = kg_string_new(""); + + kg_string_set_size(out, 0); + + //check first IDC + if(strncmp(in->str, "u2ff", 4) != 0) return; + //switch by combine types + switch((in->str)[4]){ + case '0': + divideInto2(in, partIDS1, partIDS3); + if(partIDS1->len == 0) return; + //ready each parts + generateGlyphByIDS(partIDS1, partStroke1, 1); + if(partStroke1->len == 0) return; + partStroke1 = CalcSizes(partStroke1, 0); + generateGlyphByIDS(partIDS3, partStroke3, 2); + if(partStroke3->len == 0) return; + partStroke3 = CalcSizes(partStroke3, 0); + break; + case '1': + divideInto2(in, partIDS1, partIDS3); + if(partIDS1->len == 0) return; + //ready each parts + generateGlyphByIDS(partIDS1, partStroke1, 3); + if(partStroke1->len == 0) return; + partStroke1 = CalcSizes(partStroke1, 0); + generateGlyphByIDS(partIDS3, partStroke3, 4); + if(partStroke3->len == 0) return; + partStroke3 = CalcSizes(partStroke3, 0); + break; + case '4': //full surround + case '5': //surround from above + case '6': //surround from below + case '7': //surround from left + case '8': //surround from upper left + case '9': //surround from upper right + case 'a': //surround from lower left + //case 'b': //overlaid (not supported) + divideInto2(in, partIDS1, partIDS3); + if(partIDS1->len == 0) return; + //ready each parts + generateGlyphByIDS(partIDS1, partStroke1, 5); + if(partStroke1->len == 0) return; + partStroke1 = CalcSizes(partStroke1, 0); + generateGlyphByIDS(partIDS3, partStroke3, 6); + if(partStroke3->len == 0) return; + partStroke3 = CalcSizes(partStroke3, 0); + break; + case '2': + divideInto3(in, partIDS1, partIDS2, partIDS3); + if(partIDS1->len == 0) return; + //ready each parts + generateGlyphByIDS(partIDS1, partStroke1, 1); + if(partStroke1->len == 0) return; + partStroke1 = CalcSizes(partStroke1, 0); + generateGlyphByIDS(partIDS2, partStroke2, 1); + if(partStroke2->len == 0) return; + partStroke2 = CalcSizes(partStroke2, 0); + generateGlyphByIDS(partIDS3, partStroke3, 2); + if(partStroke3->len == 0) return; + partStroke3 = CalcSizes(partStroke3, 0); + break; + case '3': + divideInto3(in, partIDS1, partIDS2, partIDS3); + if(partIDS1->len == 0) return; + //ready each parts + generateGlyphByIDS(partIDS1, partStroke1, 3); + if(partStroke1->len == 0) return; + partStroke1 = CalcSizes(partStroke1, 0); + generateGlyphByIDS(partIDS2, partStroke2, 3); + if(partStroke2->len == 0) return; + partStroke2 = CalcSizes(partStroke2, 0); + generateGlyphByIDS(partIDS3, partStroke3, 4); + if(partStroke3->len == 0) return; + partStroke3 = CalcSizes(partStroke3, 0); + break; + } + switch((in->str)[4]){ + case '0': + combineYoko2(partStroke1, partStroke3, result); + break; + case '1': + combineTate2(partStroke1, partStroke3, result); + break; + case '2': + combineYoko3(partStroke1, partStroke2, partStroke3, result); + break; + case '3': + combineTate3(partStroke1, partStroke2, partStroke3, result); + break; + case '4': //full surround + combineHame2(partStroke1, partStroke3, result, + FLAG_SURROUND_LEFT | + FLAG_SURROUND_RIGHT | + FLAG_SURROUND_TOP | + FLAG_SURROUND_BOTTOM); + break; + case '5': //surround from above + combineHame2(partStroke1, partStroke3, result, + FLAG_SURROUND_LEFT | + FLAG_SURROUND_RIGHT | + FLAG_SURROUND_TOP); + break; + case '6': //surround from below + combineHame2(partStroke1, partStroke3, result, + FLAG_SURROUND_LEFT | + FLAG_SURROUND_RIGHT | + FLAG_SURROUND_BOTTOM); + break; + case '7': //surround from left + combineHame2(partStroke1, partStroke3, result, + FLAG_SURROUND_LEFT | + FLAG_SURROUND_TOP | + FLAG_SURROUND_BOTTOM); + break; + case '8': //surround from upper left + combineHame2(partStroke1, partStroke3, result, + FLAG_SURROUND_LEFT | + FLAG_SURROUND_TOP); + break; + case '9': //surround from upper right + combineHame2(partStroke1, partStroke3, result, + FLAG_SURROUND_RIGHT | + FLAG_SURROUND_TOP); + break; + case 'a': //surround from lower left + combineHame2(partStroke1, partStroke3, result, + FLAG_SURROUND_LEFT | + FLAG_SURROUND_BOTTOM); + break; + //case 'b': //overlaid (not supported) + } + switch((in->str)[4]){ + case '0': + case '1': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'a': + //case 'b': + addStrokeWithTransform(partStroke1, 1, result, out, 1); + addStrokeWithTransform(partStroke3, 3, result, out, 1); + break; + case '2': + case '3': + addStrokeWithTransform(partStroke1, 1, result, out, 1); + addStrokeWithTransform(partStroke2, 2, result, out, 1); + addStrokeWithTransform(partStroke3, 3, result, out, 1); + break; + } +} + +void drawGlyph(const KGString *in, const int mode){ + int i, j; + int *buf; + buf = convertStroke(in->str, buf, &j); + for(i = 0; i < j; i++){ + if(mode == 0){ //normal + dfDrawFont(buf[i * 11 + 0], + buf[i * 11 + 1], + buf[i * 11 + 2], + buf[i * 11 + 3], + buf[i * 11 + 4], + buf[i * 11 + 5], + buf[i * 11 + 6], + buf[i * 11 + 7], + buf[i * 11 + 8], + buf[i * 11 + 9], + buf[i * 11 + 10]); + } + else if(mode == 1){ //without decoration + dfDrawFont(buf[i * 11 + 0], + 0, + 0, + buf[i * 11 + 3], + buf[i * 11 + 4], + buf[i * 11 + 5], + buf[i * 11 + 6], + buf[i * 11 + 7], + buf[i * 11 + 8], + buf[i * 11 + 9], + buf[i * 11 + 10]); + } + } + free(buf); +} +