0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.0.0447: getting font name does not work on X11

Problem:    Getting font name does not work on X11.
Solution:   Implement gui_mch_get_fontname() for X11.  Add more GUI tests.
            (Kazunobu Kuriyama)
This commit is contained in:
Bram Moolenaar
2017-03-12 17:10:33 +01:00
parent 454709baff
commit 8774845ce1
11 changed files with 274 additions and 19 deletions

View File

@@ -110,6 +110,7 @@ SRC_ALL = \
src/testdir/setup.vim \
src/testdir/gui_init.vim \
src/testdir/setup_gui.vim \
src/testdir/gui_preinit.vim \
src/testdir/test[0-9]*.ok \
src/testdir/test[0-9]*a.ok \
src/testdir/test_[a-z]*.ok \

View File

@@ -1992,14 +1992,40 @@ gui_mch_get_font(char_u *name, int giveErrorIfMissing)
#if defined(FEAT_EVAL) || defined(PROTO)
/*
* Return the name of font "font" in allocated memory.
* Don't know how to get the actual name, thus use the provided name.
*/
char_u *
gui_mch_get_fontname(GuiFont font UNUSED, char_u *name)
gui_mch_get_fontname(GuiFont font, char_u *name)
{
if (name == NULL)
return NULL;
return vim_strsave(name);
char_u *ret = NULL;
if (name != NULL && font == NULL)
{
/* In this case, there's no way other than doing this. */
ret = vim_strsave(name);
}
else if (font != NULL)
{
/* In this case, try to retrieve the XLFD corresponding to 'font'->fid;
* if failed, use 'name' unless it's NULL. */
unsigned long value = 0L;
if (XGetFontProperty(font, XA_FONT, &value))
{
char *xa_font_name = NULL;
xa_font_name = XGetAtomName(gui.dpy, value);
if (xa_font_name != NULL)
{
ret = vim_strsave((char_u *)xa_font_name);
XFree(xa_font_name);
}
else if (name != NULL)
ret = vim_strsave(name);
}
else if (name != NULL)
ret = vim_strsave(name);
}
return ret;
}
#endif

View File

@@ -8169,7 +8169,7 @@ hl_has_settings(int idx, int check_link)
|| HL_TABLE()[idx].sg_gui_fg_name != NULL
|| HL_TABLE()[idx].sg_gui_bg_name != NULL
|| HL_TABLE()[idx].sg_gui_sp_name != NULL
|| HL_TABLE()[idx].sg_font_name != NUL
|| HL_TABLE()[idx].sg_font_name != NULL
#endif
|| (check_link && (HL_TABLE()[idx].sg_set & SG_LINK)));
}

View File

@@ -126,7 +126,7 @@ test_gui.res: test_gui.vim
test_gui_init.res: test_gui_init.vim
@echo "$(VIMPROG)" > vimcmd
$(VIMPROG) -u NONE -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $*.vim
$(VIMPROG) -u gui_preinit.vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $*.vim
@del vimcmd
opt_test.vim: ../option.c gen_opt_test.vim

View File

@@ -129,7 +129,7 @@ test_gui.res: test_gui.vim
test_gui_init.res: test_gui_init.vim
@echo "$(VIMPROG)" > vimcmd
$(VIMPROG) -u NONE -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
$(VIMPROG) -u gui_preinit_vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
@$(DEL) vimcmd
opt_test.vim: ../option.c gen_opt_test.vim

View File

@@ -138,7 +138,7 @@ test_gui.res: test_gui.vim
test_gui_init.res: test_gui_init.vim
@echo "$(RUN_GVIMTEST_WITH_GVIMRC)" > vimcmd
$(RUN_VIMTEST) -u NONE -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
$(RUN_VIMTEST) -u gui_preinit.vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
@rm vimcmd
opt_test.vim: ../option.c gen_opt_test.vim

View File

@@ -2,4 +2,5 @@
if has('gui_athena') || has('gui_motif') || has('gui_gtk2') || has('gui_gtk3')
set guiheadroom=0
set guioptions+=p
endif

View File

@@ -0,0 +1,7 @@
" vimrc for test_gui_init.vim
" Note that this flag must be added in the .vimrc file, before switching on
" syntax or filetype recognition (when the |gvimrc| file is sourced the system
" menu has already been loaded; the ":syntax on" and ":filetype on" commands
" load the menu too).
set guioptions+=M

View File

@@ -30,6 +30,18 @@ func Test_balloon_show()
endif
endfunc
func Test_colorscheme()
let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default'
colorscheme torte
redraw!
sleep 200m
call assert_equal('dark', &background)
exec 'colorscheme' colorscheme_saved
redraw!
endfunc
func Test_getfontname_with_arg()
let skipped = ''
@@ -40,8 +52,8 @@ func Test_getfontname_with_arg()
call assert_equal('', getfontname('notexist'))
" Valid font name. This is usually the real name of 7x13 by default.
let fname = '-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1'
call assert_equal(fname, getfontname(fname))
let fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1'
call assert_match(fname, getfontname(fname))
elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
" Invalid font name. The result should be the name plus the default size.
@@ -68,8 +80,9 @@ func Test_getfontname_without_arg()
" 'expected' is the value specified by SetUp() above.
call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname)
elseif has('gui_athena') || has('gui_motif')
" 'expected' is DFLT_FONT of gui_x11.c.
call assert_equal('7x13', fname)
" 'expected' is DFLT_FONT of gui_x11.c or its real name.
let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
call assert_match(pat, fname)
elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
" 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
call assert_equal('Monospace 10', fname)
@@ -80,6 +93,12 @@ func Test_getfontname_without_arg()
endif
endfunc
func Test_getwinpos()
call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
call assert_true(getwinposx() >= 0)
call assert_true(getwinposy() >= 0)
endfunc
func Test_quoteplus()
let skipped = ''
@@ -125,6 +144,18 @@ func Test_quoteplus()
endif
endfunc
func Test_set_background()
let background_saved = &background
set background&
call assert_equal('light', &background)
set background=dark
call assert_equal('dark', &background)
let &background = background_saved
endfunc
func Test_set_balloondelay()
if !exists('+balloondelay')
return
@@ -248,6 +279,46 @@ func Test_set_balloonexpr()
let &balloonexpr = balloonexpr_saved
endfunc
" Invalid arguments are tested with test_options in conjunction with segfaults
" caused by them (Patch 8.0.0357, 24922ec233).
func Test_set_guicursor()
let guicursor_saved = &guicursor
let default = [
\ "n-v-c:block-Cursor/lCursor",
\ "ve:ver35-Cursor",
\ "o:hor50-Cursor",
\ "i-ci:ver25-Cursor/lCursor",
\ "r-cr:hor20-Cursor/lCursor",
\ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"
\ ]
" Default Value
set guicursor&
call assert_equal(join(default, ','), &guicursor)
" Argument List Example 1
let opt_list = copy(default)
let opt_list[0] = "n-c-v:block-nCursor"
exec "set guicursor=" . join(opt_list, ',')
call assert_equal(join(opt_list, ','), &guicursor)
unlet opt_list
" Argument List Example 2
let opt_list = copy(default)
let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150"
exec "set guicursor=" . join(opt_list, ',')
call assert_equal(join(opt_list, ','), &guicursor)
unlet opt_list
" 'a' Mode
set guicursor&
let &guicursor .= ',a:blinkon0'
call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor)
let &guicursor = guicursor_saved
endfunc
func Test_set_guifont()
let skipped = ''
@@ -274,11 +345,13 @@ func Test_set_guifont()
" Non-empty font list with a valid font name. Should pick up the first
" valid font.
set guifont=-notexist1-*,fixed,-notexist2-*
call assert_equal('fixed', getfontname())
let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
call assert_match(pat, getfontname())
" Empty list. Should fallback to the built-in default.
set guifont=
call assert_equal('7x13', getfontname())
let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
call assert_match(pat, getfontname())
elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
" For GTK, what we refer to as 'font names' in our manual are actually
@@ -477,10 +550,120 @@ func Test_set_guiheadroom()
endif
endfunc
func Test_getwinpos()
call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
call assert_true(getwinposx() >= 0)
call assert_true(getwinposy() >= 0)
func Test_set_guioptions()
let guioptions_saved = &guioptions
let duration = '200m'
if has('win32')
" Default Value
set guioptions&
call assert_equal('egmrLtT', &guioptions)
else
" Default Value
set guioptions&
call assert_equal('aegimrLtT', &guioptions)
" To activate scrollbars of type 'L' or 'R'.
wincmd v
redraw!
" Remove all default GUI ornaments
set guioptions-=T
exec 'sleep' . duration
call assert_equal('aegimrLt', &guioptions)
set guioptions-=t
exec 'sleep' . duration
call assert_equal('aegimrL', &guioptions)
set guioptions-=L
exec 'sleep' . duration
call assert_equal('aegimr', &guioptions)
set guioptions-=r
exec 'sleep' . duration
call assert_equal('aegim', &guioptions)
set guioptions-=m
exec 'sleep' . duration
call assert_equal('aegi', &guioptions)
" Try non-default GUI ornaments
set guioptions+=l
exec 'sleep' . duration
call assert_equal('aegil', &guioptions)
set guioptions-=l
exec 'sleep' . duration
call assert_equal('aegi', &guioptions)
set guioptions+=R
exec 'sleep' . duration
call assert_equal('aegiR', &guioptions)
set guioptions-=R
exec 'sleep' . duration
call assert_equal('aegi', &guioptions)
set guioptions+=b
exec 'sleep' . duration
call assert_equal('aegib', &guioptions)
set guioptions+=h
exec 'sleep' . duration
call assert_equal('aegibh', &guioptions)
set guioptions-=h
exec 'sleep' . duration
call assert_equal('aegib', &guioptions)
set guioptions-=b
exec 'sleep' . duration
call assert_equal('aegi', &guioptions)
set guioptions+=v
exec 'sleep' . duration
call assert_equal('aegiv', &guioptions)
set guioptions-=v
exec 'sleep' . duration
call assert_equal('aegi', &guioptions)
if has('gui_motif')
set guioptions+=F
exec 'sleep' . duration
call assert_equal('aegiF', &guioptions)
set guioptions-=F
exec 'sleep' . duration
call assert_equal('aegi', &guioptions)
endif
" Restore GUI ornaments to the default state.
set guioptions+=m
exec 'sleep' . duration
call assert_equal('aegim', &guioptions)
set guioptions+=r
exec 'sleep' . duration
call assert_equal('aegimr', &guioptions)
set guioptions+=L
exec 'sleep' . duration
call assert_equal('aegimrL', &guioptions)
set guioptions+=t
exec 'sleep' . duration
call assert_equal('aegimrLt', &guioptions)
set guioptions+=T
exec 'sleep' . duration
call assert_equal("aegimrLtT", &guioptions)
wincmd o
redraw!
endif
let &guioptions = guioptions_saved
endfunc
func Test_set_guipty()
let guipty_saved = &guipty
" Default Value
set guipty&
call assert_equal(1, &guipty)
set noguipty
call assert_equal(0, &guipty)
let &guipty = guipty_saved
endfunc
func Test_shell_command()
@@ -490,6 +673,19 @@ func Test_shell_command()
bwipe!
endfunc
func Test_syntax_colortest()
runtime syntax/colortest.vim
redraw!
sleep 200m
bwipe!
endfunc
func Test_set_term()
" It's enough to check the current value since setting 'term' to anything
" other than builtin_gui makes no sense at all.
call assert_equal('builtin_gui', &term)
endfunc
func Test_windowid_variable()
if g:x11_based_gui || has('win32')
call assert_true(v:windowid > 0)

View File

@@ -36,3 +36,25 @@ func Test_set_guiheadroom()
throw skipped
endif
endfunc
func Test_set_guioptions_for_M()
sleep 200ms
" Check if the 'M' option is included.
call assert_match('.*M.*', &guioptions)
endfunc
func Test_set_guioptions_for_p()
let skipped = ''
if !g:x11_based_gui
let skipped = g:not_supported . '''p'' of guioptions'
else
sleep 200ms
" Check if the 'p' option is included.
call assert_match('.*p.*', &guioptions)
endif
if !empty(skipped)
throw skipped
endif
endfunc

View File

@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
447,
/**/
446,
/**/