Diff

Differences From Artifact [b611496fca]:

To Artifact [7e7643ffd4]:


2897
2898
2899
2900
2901
2902
2903
2904

2905
2906
2907
2908
2909
2910
2911
2912
2913

2914
2915
2916




2917
2918
2919
2920
2921
2922
2923
2897
2898
2899
2900
2901
2902
2903

2904
2905
2906
2907
2908
2909
2910
2911


2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926







-
+







-
-
+



+
+
+
+








/*
 * Draw a line of text in the window, at given character
 * coordinates, in given attributes.
 *
 * We are allowed to fiddle with the contents of `text'.
 */
void do_text(Context ctx, int x, int y, char *text, int len,
void do_text(Context ctx, int x, int y, wchar_t *text, int len,
	     unsigned long attr, int lattr)
{
    COLORREF fg, bg, t;
    int nfg, nbg, nfont;
    HDC hdc = ctx;
    RECT line_box;
    int force_manual_underline = 0;
    int fnt_width = font_width * (1 + (lattr != LATTR_NORM));
    int char_width = fnt_width;
    int fnt_width, char_width;
    int text_adjust = 0;
    static int *IpDx = 0, IpDxLEN = 0;

    lattr &= LATTR_MODE;

    char_width = fnt_width = font_width * (1 + (lattr != LATTR_NORM));

    if (attr & ATTR_WIDE)
	char_width *= 2;

    if (len > IpDxLEN || IpDx[0] != char_width) {
	int i;
	if (len > IpDxLEN) {
	    sfree(IpDx);
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981

















2982
2983
2984
2985
2986
2987
2988
2989
2990







2991
2992
2993

2994
2995



2996
2997
2998
2999
3000

3001
3002
3003
3004
3005
3006
3007
2960
2961
2962
2963
2964
2965
2966


















2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983









2984
2985
2986
2987
2988
2989
2990

2991

2992


2993
2994
2995

2996
2997
2998

2999
3000
3001
3002
3003
3004
3005
3006







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-

-
+
-
-
+
+
+
-



-
+







	    nfont |= FONT_WIDE + FONT_HIGH;
	    break;
	}
    if (attr & ATTR_NARROW)
	nfont |= FONT_NARROW;

    /* Special hack for the VT100 linedraw glyphs. */
    if ((attr & CSET_MASK) == 0x2300) {
	if (text[0] >= (char) 0xBA && text[0] <= (char) 0xBD) {
	    switch ((unsigned char) (text[0])) {
	      case 0xBA:
		text_adjust = -2 * font_height / 5;
		break;
	      case 0xBB:
		text_adjust = -1 * font_height / 5;
		break;
	      case 0xBC:
		text_adjust = font_height / 5;
		break;
	      case 0xBD:
		text_adjust = 2 * font_height / 5;
		break;
	    }
	    if (lattr == LATTR_TOP || lattr == LATTR_BOT)
		text_adjust *= 2;
    if (text[0] >= 0x23BA && text[0] <= 0x23BD) {
	switch ((unsigned char) (text[0])) {
	  case 0xBA:
	    text_adjust = -2 * font_height / 5;
	    break;
	  case 0xBB:
	    text_adjust = -1 * font_height / 5;
	    break;
	  case 0xBC:
	    text_adjust = font_height / 5;
	    break;
	  case 0xBD:
	    text_adjust = 2 * font_height / 5;
	    break;
	}
	if (lattr == LATTR_TOP || lattr == LATTR_BOT)
	    text_adjust *= 2;
	    attr &= ~CSET_MASK;
	    text[0] = (char) (ucsdata.unitab_xterm['q'] & CHAR_MASK);
	    attr |= (ucsdata.unitab_xterm['q'] & CSET_MASK);
	    if (attr & ATTR_UNDER) {
		attr &= ~ATTR_UNDER;
		force_manual_underline = 1;
	    }
	}
    }
	text[0] = ucsdata.unitab_xterm['q'];
	if (attr & ATTR_UNDER) {
	    attr &= ~ATTR_UNDER;
	    force_manual_underline = 1;
	}
    }


    /* Anything left as an original character set is unprintable. */
    if (DIRECT_CHAR(attr)) {
    if (DIRECT_CHAR(text[0])) {
	attr &= ~CSET_MASK;
	attr |= 0xFF00;
	int i;
	for (i = 0; i < len; i++)
	    text[i] = 0xFFFD;
	memset(text, 0xFD, len);
    }

    /* OEM CP */
    if ((attr & CSET_MASK) == ATTR_OEMCP)
    if ((text[0] & CSET_MASK) == CSET_OEMCP)
	nfont |= FONT_OEM;

    nfg = ((attr & ATTR_FGMASK) >> ATTR_FGSHIFT);
    nfg = 2 * (nfg & 0xF) + (nfg & 0x10 ? 1 : 0);
    nbg = ((attr & ATTR_BGMASK) >> ATTR_BGSHIFT);
    nbg = 2 * (nbg & 0xF) + (nbg & 0x10 ? 1 : 0);
    if (bold_mode == BOLD_FONT && (attr & ATTR_BOLD))
3040
3041
3042
3043
3044
3045
3046
3047

3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061



3062
3063
3064

3065
3066
3067
3068


3069
3070

3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089












3090
3091
3092

3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106

3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119

3120
3121
3122
3123
3124
3125
3126
3039
3040
3041
3042
3043
3044
3045

3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065

3066
3067
3068
3069
3070
3071
3072
3073

3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092

3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106

3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120

3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133

3134
3135
3136
3137
3138
3139
3140
3141







-
+














+
+
+


-
+




+
+

-
+


















-
+
+
+
+
+
+
+
+
+
+
+
+


-
+













-
+












-
+







    line_box.bottom = y + font_height;

    /* Only want the left half of double width lines */
    if (line_box.right > font_width*term->cols+offset_width)
	line_box.right = font_width*term->cols+offset_width;

    /* We're using a private area for direct to font. (512 chars.) */
    if (ucsdata.dbcs_screenfont && (attr & CSET_MASK) == ATTR_ACP) {
    if (ucsdata.dbcs_screenfont && (text[0] & CSET_MASK) == CSET_ACP) {
	/* Ho Hum, dbcs fonts are a PITA! */
	/* To display on W9x I have to convert to UCS */
	static wchar_t *uni_buf = 0;
	static int uni_len = 0;
	int nlen, mptr;
	if (len > uni_len) {
	    sfree(uni_buf);
	    uni_len = len;
	    uni_buf = snewn(uni_len, wchar_t);
	}

	for(nlen = mptr = 0; mptr<len; mptr++) {
	    uni_buf[nlen] = 0xFFFD;
	    if (IsDBCSLeadByteEx(ucsdata.font_codepage, (BYTE) text[mptr])) {
		char dbcstext[2];
		dbcstext[0] = text[mptr] & 0xFF;
		dbcstext[1] = text[mptr+1] & 0xFF;
		IpDx[nlen] += char_width;
	        MultiByteToWideChar(ucsdata.font_codepage, MB_USEGLYPHCHARS,
				   text+mptr, 2, uni_buf+nlen, 1);
				    dbcstext, 2, uni_buf+nlen, 1);
		mptr++;
	    }
	    else
	    {
		char dbcstext[1];
		dbcstext[0] = text[mptr] & 0xFF;
	        MultiByteToWideChar(ucsdata.font_codepage, MB_USEGLYPHCHARS,
				   text+mptr, 1, uni_buf+nlen, 1);
				    dbcstext, 1, uni_buf+nlen, 1);
	    }
	    nlen++;
	}
	if (nlen <= 0)
	    return;		       /* Eeek! */

	ExtTextOutW(hdc, x,
		    y - font_height * (lattr == LATTR_BOT) + text_adjust,
		    ETO_CLIPPED | ETO_OPAQUE, &line_box, uni_buf, nlen, IpDx);
	if (bold_mode == BOLD_SHADOW && (attr & ATTR_BOLD)) {
	    SetBkMode(hdc, TRANSPARENT);
	    ExtTextOutW(hdc, x - 1,
			y - font_height * (lattr ==
					   LATTR_BOT) + text_adjust,
			ETO_CLIPPED, &line_box, uni_buf, nlen, IpDx);
	}

	IpDx[0] = -1;
    } else if (DIRECT_FONT(attr)) {
    } else if (DIRECT_FONT(text[0])) {
	static char *directbuf = NULL;
	static int directlen = 0;
	int i;
	if (len > directlen) {
	    directlen = len;
	    directbuf = sresize(directbuf, directlen, char);
	}

	for (i = 0; i < len; i++)
	    directbuf[i] = text[i] & 0xFF;

	ExtTextOut(hdc, x,
		   y - font_height * (lattr == LATTR_BOT) + text_adjust,
		   ETO_CLIPPED | ETO_OPAQUE, &line_box, text, len, IpDx);
		   ETO_CLIPPED | ETO_OPAQUE, &line_box, directbuf, len, IpDx);
	if (bold_mode == BOLD_SHADOW && (attr & ATTR_BOLD)) {
	    SetBkMode(hdc, TRANSPARENT);

	    /* GRR: This draws the character outside it's box and can leave
	     * 'droppings' even with the clip box! I suppose I could loop it
	     * one character at a time ... yuk. 
	     * 
	     * Or ... I could do a test print with "W", and use +1 or -1 for this
	     * shift depending on if the leftmost column is blank...
	     */
	    ExtTextOut(hdc, x - 1,
		       y - font_height * (lattr ==
					  LATTR_BOT) + text_adjust,
		       ETO_CLIPPED, &line_box, text, len, IpDx);
		       ETO_CLIPPED, &line_box, directbuf, len, IpDx);
	}
    } else {
	/* And 'normal' unicode characters */
	static WCHAR *wbuf = NULL;
	static int wlen = 0;
	int i;
	if (wlen < len) {
	    sfree(wbuf);
	    wlen = len;
	    wbuf = snewn(wlen, WCHAR);
	}
	for (i = 0; i < len; i++)
	    wbuf[i] = (WCHAR) ((attr & CSET_MASK) + (text[i] & CHAR_MASK));
	    wbuf[i] = text[i];

	/* print Glyphs as they are, without Windows' Shaping*/
	exact_textout(hdc, x, y - font_height * (lattr == LATTR_BOT) + text_adjust,
		      &line_box, wbuf, len, IpDx);
/*	ExtTextOutW(hdc, x,
		    y - font_height * (lattr == LATTR_BOT) + text_adjust,
		    ETO_CLIPPED | ETO_OPAQUE, &line_box, wbuf, len, IpDx);
3147
3148
3149
3150
3151
3152
3153
3154

3155
3156
3157
3158
3159
3160
3161
3162
3163
3164

3165
3166
3167
3168
3169
3170
3171
3162
3163
3164
3165
3166
3167
3168

3169
3170
3171
3172
3173
3174
3175
3176
3177
3178

3179
3180
3181
3182
3183
3184
3185
3186







-
+









-
+







	MoveToEx(hdc, x, y + dec, NULL);
	LineTo(hdc, x + len * char_width, y + dec);
	oldpen = SelectObject(hdc, oldpen);
	DeleteObject(oldpen);
    }
}

void do_cursor(Context ctx, int x, int y, char *text, int len,
void do_cursor(Context ctx, int x, int y, wchar_t *text, int len,
	       unsigned long attr, int lattr)
{

    int fnt_width;
    int char_width;
    HDC hdc = ctx;
    int ctype = cfg.cursor_type;

    if ((attr & TATTR_ACTCURS) && (ctype == 0 || term->big_cursor)) {
	if (((attr & CSET_MASK) | (unsigned char) *text) != UCSWIDE) {
	if (*text != UCSWIDE) {
	    do_text(ctx, x, y, text, len, attr, lattr);
	    return;
	}
	ctype = 2;
	attr |= TATTR_RIGHTCURS;
    }

3234
3235
3236
3237
3238
3239
3240
3241

3242
3243
3244

3245
3246
3247

3248
3249
3250
3251
3252
3253
3254
3255

3256
3257
3258

3259
3260

3261
3262
3263
3264
3265
3266
3267
3268
3269


3270
3271
3272
3273
3274
3275
3276
3249
3250
3251
3252
3253
3254
3255

3256
3257
3258

3259
3260
3261

3262
3263
3264
3265
3266
3267
3268
3269

3270
3271
3272

3273
3274

3275
3276
3277
3278
3279
3280
3281
3282


3283
3284
3285
3286
3287
3288
3289
3290
3291







-
+


-
+


-
+







-
+


-
+

-
+







-
-
+
+








    /* If the font max is the same as the font ave width then this
     * function is a no-op.
     */
    if (!font_dualwidth) return 1;

    switch (uc & CSET_MASK) {
      case ATTR_ASCII:
      case CSET_ASCII:
	uc = ucsdata.unitab_line[uc & 0xFF];
	break;
      case ATTR_LINEDRW:
      case CSET_LINEDRW:
	uc = ucsdata.unitab_xterm[uc & 0xFF];
	break;
      case ATTR_SCOACS:
      case CSET_SCOACS:
	uc = ucsdata.unitab_scoacs[uc & 0xFF];
	break;
    }
    if (DIRECT_FONT(uc)) {
	if (ucsdata.dbcs_screenfont) return 1;

	/* Speedup, I know of no font where ascii is the wrong width */
	if ((uc&CHAR_MASK) >= ' ' && (uc&CHAR_MASK)<= '~') 
	if ((uc&~CSET_MASK) >= ' ' && (uc&~CSET_MASK)<= '~')
	    return 1;

	if ( (uc & CSET_MASK) == ATTR_ACP ) {
	if ( (uc & CSET_MASK) == CSET_ACP ) {
	    SelectObject(hdc, fonts[FONT_NORMAL]);
	} else if ( (uc & CSET_MASK) == ATTR_OEMCP ) {
	} else if ( (uc & CSET_MASK) == CSET_OEMCP ) {
	    another_font(FONT_OEM);
	    if (!fonts[FONT_OEM]) return 0;

	    SelectObject(hdc, fonts[FONT_OEM]);
	} else
	    return 0;

	if ( GetCharWidth32(hdc, uc&CHAR_MASK, uc&CHAR_MASK, &ibuf) != 1 && 
	     GetCharWidth(hdc, uc&CHAR_MASK, uc&CHAR_MASK, &ibuf) != 1)
	if ( GetCharWidth32(hdc, uc&~CSET_MASK, uc&~CSET_MASK, &ibuf) != 1 &&
	     GetCharWidth(hdc, uc&~CSET_MASK, uc&~CSET_MASK, &ibuf) != 1)
	    return 0;
    } else {
	/* Speedup, I know of no font where ascii is the wrong width */
	if (uc >= ' ' && uc <= '~') return 1;

	SelectObject(hdc, fonts[FONT_NORMAL]);
	if ( GetCharWidth32W(hdc, uc, uc, &ibuf) == 1 )