Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nx-libs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dimbor
nx-libs
Commits
acd45283
Commit
acd45283
authored
Apr 09, 2020
by
Ulrich Sibiller
Committed by
Mike Gabriel
May 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Font.c: cleanup
reformat, whitespace, code simplification, FIXMEs
parent
92589f41
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
77 deletions
+72
-77
Font.c
nx-X11/programs/Xserver/hw/nxagent/Font.c
+72
-77
No files found.
nx-X11/programs/Xserver/hw/nxagent/Font.c
View file @
acd45283
...
...
@@ -205,12 +205,6 @@ void nxagentFreeFontCache(void)
void
nxagentListRemoteFonts
(
const
char
*
searchPattern
,
const
int
maxNames
)
{
char
**
xList
;
int
xLen
=
0
;
const
char
*
patterns
[]
=
{
"*"
,
"-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
};
int
patternsQt
=
2
;
if
(
NXDisplayError
(
nxagentDisplay
)
==
1
)
{
return
;
...
...
@@ -233,9 +227,13 @@ void nxagentListRemoteFonts(const char *searchPattern, const int maxNames)
* select the 'real' fonts.
*/
for
(
int
p
=
0
;
p
<
patternsQt
;
p
++
)
const
char
*
patterns
[]
=
{
"*"
,
"-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
};
const
int
numPatterns
=
2
;
for
(
int
p
=
0
;
p
<
numPatterns
;
p
++
)
{
xList
=
XListFonts
(
nxagentDisplay
,
patterns
[
p
],
maxNames
,
&
xLen
);
int
xLen
=
0
;
char
**
xList
=
XListFonts
(
nxagentDisplay
,
patterns
[
p
],
maxNames
,
&
xLen
);
#ifdef NXAGENT_FONTMATCH_DEBUG
fprintf
(
stderr
,
"nxagentListRemoteFonts: NXagent remote list [%s] has %d elements.
\n
"
,
patterns
[
p
],
xLen
);
...
...
@@ -282,7 +280,8 @@ void nxagentListRemoteAddName(const char *name, int status)
#ifdef NXAGENT_FONTMATCH_DEBUG
fprintf
(
stderr
,
"Font: Font# %d, [%s] change status to %s
\n
"
,
pos
,
nxagentRemoteFontList
.
list
[
pos
]
->
name
,
nxagentRemoteFontList
.
list
[
pos
]
->
status
?
"OK"
:
"deleted"
);
pos
,
nxagentRemoteFontList
.
list
[
pos
]
->
name
,
nxagentRemoteFontList
.
list
[
pos
]
->
status
?
"OK"
:
"deleted"
);
#endif
}
return
;
...
...
@@ -290,6 +289,7 @@ void nxagentListRemoteAddName(const char *name, int status)
if
(
nxagentRemoteFontList
.
length
==
nxagentRemoteFontList
.
listSize
)
{
/* FIXME: if realloc fails the pointer is lost! */
nxagentRemoteFontList
.
list
=
realloc
(
nxagentRemoteFontList
.
list
,
sizeof
(
nxagentFontRecPtr
)
*
(
nxagentRemoteFontList
.
listSize
+
1000
));
...
...
@@ -365,6 +365,7 @@ Bool nxagentFontFind(const char *name, int *pos)
*
pos
=
0
;
return
False
;
}
int
low
=
0
;
int
high
=
nxagentRemoteFontList
.
length
-
1
;
int
iter
=
0
;
...
...
@@ -389,7 +390,7 @@ Bool nxagentFontFind(const char *name, int *pos)
}
break
;
}
*
pos
=
(
res
==
0
)
?*
pos
:
lpos
;
*
pos
=
(
res
==
0
)
?
*
pos
:
lpos
;
#ifdef NXAGENT_FONTMATCH_DEBUG
if
(
res
==
0
)
...
...
@@ -399,14 +400,13 @@ Bool nxagentFontFind(const char *name, int *pos)
#endif
return
(
res
==
0
);
}
Bool
nxagentFontLookUp
(
const
char
*
name
)
{
int
i
;
if
(
name
!=
NULL
&&
strlen
(
name
)
==
0
)
if
(
name
&&
strlen
(
name
)
==
0
)
{
return
0
;
}
...
...
@@ -455,49 +455,47 @@ Bool nxagentFontLookUp(const char *name)
Bool
nxagentRealizeFont
(
ScreenPtr
pScreen
,
FontPtr
pFont
)
{
void
*
priv
;
Atom
name_atom
,
value_atom
;
int
nprops
;
FontPropPtr
props
;
int
i
;
const
char
*
name
;
char
*
origName
=
(
char
*
)
pScreen
;
#ifdef HAS_XFONT2
xfont2_font_set_private
(
pFont
,
nxagentFontPrivateIndex
,
NULL
);
#else
FontSetPrivate
(
pFont
,
nxagentFontPrivateIndex
,
NULL
);
#endif
/* HAS_XFONT2 */
name_atom
=
MakeAtom
(
"FONT"
,
4
,
True
);
value_atom
=
0L
;
Atom
name_atom
=
MakeAtom
(
"FONT"
,
4
,
True
);
Atom
value_atom
=
0L
;
nprops
=
pFont
->
info
.
nprops
;
props
=
pFont
->
info
.
props
;
int
nprops
=
pFont
->
info
.
nprops
;
FontPropPtr
props
=
pFont
->
info
.
props
;
for
(
i
=
0
;
i
<
nprops
;
i
++
)
if
((
Atom
)
props
[
i
].
name
==
name_atom
)
{
for
(
int
i
=
0
;
i
<
nprops
;
i
++
)
{
if
((
Atom
)
props
[
i
].
name
==
name_atom
)
{
value_atom
=
props
[
i
].
value
;
break
;
}
}
if
(
!
value_atom
)
return
False
;
if
(
!
value_atom
)
return
False
;
name
=
NameForAtom
(
value_atom
);
const
char
*
name
=
NameForAtom
(
value_atom
);
#ifdef NXAGENT_FONTCACHE_DEBUG
fprintf
(
stderr
,
"Font: nxagentRealizeFont, realizing font: %s
\n
"
,
validateString
(
name
));
fprintf
(
stderr
,
" atom: %ld
\n
"
,
value_atom
);
fprintf
(
stderr
,
"Font: Cache dump:
\n
"
);
for
(
i
=
0
;
i
<
CACHE_INDEX
;
i
++
)
for
(
int
i
=
0
;
i
<
CACHE_INDEX
;
i
++
)
{
fprintf
(
stderr
,
"nxagentFontCache.entry[%d]->name: %s font_struct at %p
\n
"
,
i
,
CACHE_NAME
(
i
),
CACHE_FSTRUCT
(
i
));
}
#endif
if
(
!
name
)
return
False
;
if
(
!
name
)
return
False
;
char
*
origName
=
(
char
*
)
pScreen
;
if
((
strcasecmp
(
origName
,
name
)
!=
0
)
&&
!
strchr
(
origName
,
'*'
))
{
#ifdef NXAGENT_FONTMATCH_DEBUG
...
...
@@ -508,7 +506,7 @@ Bool nxagentRealizeFont(ScreenPtr pScreen, FontPtr pFont)
name
=
origName
;
}
priv
=
(
void
*
)
malloc
(
sizeof
(
nxagentPrivFont
));
void
*
priv
=
(
void
*
)
malloc
(
sizeof
(
nxagentPrivFont
));
#ifdef HAS_XFONT2
xfont2_font_set_private
(
pFont
,
nxagentFontPrivateIndex
,
priv
);
#else
...
...
@@ -517,22 +515,23 @@ Bool nxagentRealizeFont(ScreenPtr pScreen, FontPtr pFont)
nxagentFontPriv
(
pFont
)
->
mirrorID
=
0
;
for
(
i
=
0
;
i
<
nxagentFontCache
.
index
;
i
++
)
int
fci
;
for
(
fci
=
0
;
fci
<
nxagentFontCache
.
index
;
fci
++
)
{
/* if (value_atom == CACHE_ATOM(i))*/
if
(
strcasecmp
(
CACHE_NAME
(
i
),
name
)
==
0
)
/* if (value_atom == CACHE_ATOM(i))*/
if
(
strcasecmp
(
CACHE_NAME
(
fc
i
),
name
)
==
0
)
{
#ifdef NXAGENT_FONTCACHE_DEBUG
fprintf
(
stderr
,
"Font: nxagentFontCache hit [%s] = [%s]!
\n
"
,
CACHE_NAME
(
i
),
validateString
(
name
));
fprintf
(
stderr
,
"Font: nxagentFontCache hit [%s] = [%s]!
\n
"
,
CACHE_NAME
(
fc
i
),
validateString
(
name
));
#endif
break
;
}
}
if
(
i
<
CACHE_INDEX
)
if
(
fc
i
<
CACHE_INDEX
)
{
nxagentFontPriv
(
pFont
)
->
font_struct
=
CACHE_FSTRUCT
(
i
);
nxagentFontPriv
(
pFont
)
->
font_struct
=
CACHE_FSTRUCT
(
fc
i
);
strcpy
(
nxagentFontPriv
(
pFont
)
->
fontName
,
name
);
}
else
...
...
@@ -543,6 +542,7 @@ Bool nxagentRealizeFont(ScreenPtr pScreen, FontPtr pFont)
if
(
CACHE_INDEX
==
CACHE_SIZE
)
{
/* FIXME: if realloc fails the pointer is lost */
CACHE_ENTRY_PTR
=
realloc
(
CACHE_ENTRY_PTR
,
sizeof
(
nxCacheFontEntryRecPtr
)
*
(
CACHE_SIZE
+
100
));
if
(
CACHE_ENTRY_PTR
==
NULL
)
...
...
@@ -580,9 +580,9 @@ Bool nxagentRealizeFont(ScreenPtr pScreen, FontPtr pFont)
strcpy
(
nxagentFontPriv
(
pFont
)
->
fontName
,
name
);
if
(
nxagentFontPriv
(
pFont
)
->
font_struct
!=
NULL
)
{
CACHE_ATOM
(
i
)
=
value_atom
;
strcpy
(
CACHE_NAME
(
i
),
name
);
CACHE_FSTRUCT
(
i
)
=
nxagentFontPriv
(
pFont
)
->
font_struct
;
CACHE_ATOM
(
fc
i
)
=
value_atom
;
strcpy
(
CACHE_NAME
(
fc
i
),
name
);
CACHE_FSTRUCT
(
fc
i
)
=
nxagentFontPriv
(
pFont
)
->
font_struct
;
CACHE_INDEX
++
;
nxagentFontPriv
(
pFont
)
->
mirrorID
=
FakeClientID
(
serverClient
->
index
);
...
...
@@ -611,8 +611,10 @@ Bool nxagentRealizeFont(ScreenPtr pScreen, FontPtr pFont)
}
}
else
{
fprintf
(
stderr
,
"Font: nxagentRealizeFont OK realizing font Font=%s
\n
"
,
validateString
(
name
));
}
#endif
...
...
@@ -627,11 +629,11 @@ Bool nxagentUnrealizeFont(ScreenPtr pScreen, FontPtr pFont)
{
if
(
nxagentFontStruct
(
pFont
))
{
int
i
;
int
fc
i
;
for
(
i
=
0
;
i
<
CACHE_INDEX
;
i
++
)
for
(
fci
=
0
;
fci
<
CACHE_INDEX
;
fc
i
++
)
{
if
(
CACHE_FSTRUCT
(
i
)
==
nxagentFontStruct
(
pFont
))
if
(
CACHE_FSTRUCT
(
fc
i
)
==
nxagentFontStruct
(
pFont
))
{
#ifdef NXAGENT_FONTCACHE_DEBUG
fprintf
(
stderr
,
"nxagentUnrealizeFont: Not freeing the font in cache.
\n
"
);
...
...
@@ -641,7 +643,7 @@ Bool nxagentUnrealizeFont(ScreenPtr pScreen, FontPtr pFont)
}
}
if
(
i
==
CACHE_INDEX
)
if
(
fc
i
==
CACHE_INDEX
)
{
/*
* This font is not in the cache.
...
...
@@ -649,7 +651,7 @@ Bool nxagentUnrealizeFont(ScreenPtr pScreen, FontPtr pFont)
#ifdef NXAGENT_FONTCACHE_DEBUG
fprintf
(
stderr
,
"nxagentUnrealizeFont: Freeing font not found in cache '%d'
\n
"
,
CACHE_ATOM
(
i
));
CACHE_ATOM
(
fc
i
));
#endif
XFreeFont
(
nxagentDisplay
,
nxagentFontStruct
(
pFont
));
...
...
@@ -737,7 +739,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
#ifdef WARNING
if
(
nxagentVerbose
==
1
)
{
fprintf
(
stderr
,
"nxagentLoadBestQueryFont: WARNING! Font name in non standard format.
\n
"
);
fprintf
(
stderr
,
"nxagentLoadBestQueryFont: WARNING! Font name in non standard format.
\n
"
);
}
#endif
}
...
...
@@ -765,7 +767,6 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
if
(
numSearchFields
>
FIELDS
)
{
tempWeight
=
0
;
for
(
int
j
=
0
;
j
<
FIELDS
;
j
++
)
...
...
@@ -781,7 +782,6 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
tempWeight
<<=
1
;
}
}
if
(
tempWeight
>
weight
)
...
...
@@ -870,7 +870,8 @@ static void nxagentCollectFailedFont(FontPtr fpt, XID id)
nxagentFailedToReconnectFonts
.
font
=
malloc
(
nxagentFailedToReconnectFonts
.
size
*
sizeof
(
FontPtr
));
nxagentFailedToReconnectFonts
.
id
=
malloc
(
nxagentFailedToReconnectFonts
.
size
*
sizeof
(
XID
));
nxagentFailedToReconnectFonts
.
id
=
malloc
(
nxagentFailedToReconnectFonts
.
size
*
sizeof
(
XID
));
if
(
nxagentFailedToReconnectFonts
.
font
==
NULL
||
nxagentFailedToReconnectFonts
.
id
==
NULL
)
{
...
...
@@ -889,6 +890,7 @@ static void nxagentCollectFailedFont(FontPtr fpt, XID id)
{
nxagentFailedToReconnectFonts
.
size
*=
2
;
/* FIXME: if realloc fails the pointer is lost */
nxagentFailedToReconnectFonts
.
font
=
realloc
(
nxagentFailedToReconnectFonts
.
font
,
nxagentFailedToReconnectFonts
.
size
*
sizeof
(
FontPtr
));
...
...
@@ -1029,7 +1031,7 @@ static void nxagentCleanCacheAfterReconnect(void)
for
(
int
i
=
0
;
i
<
CACHE_INDEX
;
i
++
)
{
if
(
CACHE_FSTRUCT
(
i
)
==
NULL
)
if
(
CACHE_FSTRUCT
(
i
)
==
NULL
)
{
SAFE_XFree
(
CACHE_NAME
(
i
));
real_size
--
;
...
...
@@ -1042,7 +1044,8 @@ static void nxagentCleanCacheAfterReconnect(void)
nxCacheFontEntryRecPtr
swapEntryPtr
;
/* Find - first bad occurrence if exist. */
while
((
i
<
real_size
)
&&
CACHE_FSTRUCT
(
i
))
i
++
;
while
((
i
<
real_size
)
&&
CACHE_FSTRUCT
(
i
))
i
++
;
/* Really nothing more to do. */
if
(
i
==
real_size
)
...
...
@@ -1123,13 +1126,12 @@ Bool nxagentReconnectAllFonts(void *p0)
static
void
nxagentFailedFontReconnect
(
FontPtr
pFont
,
XID
param1
,
void
*
param2
)
{
int
i
;
nxagentPrivFont
*
privFont
;
Bool
*
pBool
=
(
Bool
*
)
param2
;
if
(
pFont
==
NULL
)
return
;
privFont
=
nxagentFontPriv
(
pFont
);
nxagentPrivFont
*
privFont
=
nxagentFontPriv
(
pFont
);
#ifdef NXAGENT_RECONNECT_FONT_DEBUG
fprintf
(
stderr
,
"nxagentFailedFontReconnect: pFont %p - XID %lx - name %s
\n
"
,
...
...
@@ -1211,15 +1213,7 @@ static void nxagentFreeFailedToReconnectFonts(void)
Bool
nxagentReconnectFailedFonts
(
void
*
p0
)
{
int
attempt
=
1
;
const
int
maxAttempt
=
5
;
char
**
fontPaths
,
**
localFontPaths
,
**
newFontPaths
;
char
fontServerPath
[
256
]
=
""
;
int
nPaths
=
0
;
Bool
repeat
=
True
;
Bool
fontSuccess
=
True
;
reconnectFlexibility
=
*
((
int
*
)
p0
);
...
...
@@ -1239,20 +1233,25 @@ Bool nxagentReconnectFailedFonts(void *p0)
fprintf
(
stderr
,
"nxagentReconnectFailedFonts: font server path [%s]
\n
"
,
fontServerPath
);
#endif
fontPaths
=
XGetFontPath
(
nxagentDisplay
,
&
nPaths
);
int
nPaths
=
0
;
char
**
fontPaths
=
XGetFontPath
(
nxagentDisplay
,
&
nPaths
);
char
**
newFontPaths
=
malloc
((
nPaths
+
1
)
*
sizeof
(
char
*
));
if
((
newFontPaths
=
malloc
((
nPaths
+
1
)
*
sizeof
(
char
*
)))
==
NULL
)
if
(
newFontPaths
==
NULL
)
{
FatalError
(
"nxagentReconnectFailedFonts: malloc failed."
);
}
memcpy
(
newFontPaths
,
fontPaths
,
nPaths
*
sizeof
(
char
*
));
localFontPaths
=
newFontPaths
;
char
**
localFontPaths
=
newFontPaths
;
localFontPaths
+=
nPaths
;
*
localFontPaths
=
fontServerPath
;
while
(
repeat
)
int
attempt
=
1
;
const
int
maxAttempt
=
5
;
Bool
repeat
=
True
;
while
(
repeat
)
{
#ifdef NXAGENT_RECONNECT_FONT_DEBUG
fprintf
(
stderr
,
"nxagentReconnectFailedFonts: attempt [%d].
\n
"
,
attempt
);
...
...
@@ -1264,11 +1263,11 @@ Bool nxagentReconnectFailedFonts(void *p0)
nxagentFreeRemoteFontList
(
&
nxagentRemoteFontList
);
nxagentListRemoteFonts
(
"*"
,
nxagentMaxFontNames
);
for
(
int
i
=
0
;
i
<
nxagentFailedToReconnectFonts
.
index
;
i
++
)
for
(
int
i
=
0
;
i
<
nxagentFailedToReconnectFonts
.
index
;
i
++
)
{
fontSuccess
=
True
;
Bool
fontSuccess
=
True
;
if
(
nxagentFailedToReconnectFonts
.
font
[
i
])
if
(
nxagentFailedToReconnectFonts
.
font
[
i
])
{
nxagentFailedFontReconnect
(
nxagentFailedToReconnectFonts
.
font
[
i
],
nxagentFailedToReconnectFonts
.
id
[
i
],
...
...
@@ -1282,7 +1281,6 @@ Bool nxagentReconnectFailedFonts(void *p0)
{
repeat
=
True
;
}
}
}
...
...
@@ -1334,9 +1332,9 @@ Bool nxagentDisconnectAllFonts(void)
FindClientResourcesByType
(
clients
[
serverClient
->
index
],
RT_NX_FONT
,
(
FindResType
)
nxagentFontDisconnect
,
&
fontSuccess
);
for
(
int
cid
=
0
;
cid
<
MAXCLIENTS
;
cid
++
)
for
(
int
cid
=
0
;
cid
<
MAXCLIENTS
;
cid
++
)
{
if
(
clients
[
cid
]
&&
fontSuccess
)
if
(
clients
[
cid
]
&&
fontSuccess
)
{
FindClientResourcesByType
(
clients
[
cid
],
RT_FONT
,
(
FindResType
)
nxagentFontDisconnect
,
&
fontSuccess
);
...
...
@@ -1505,10 +1503,7 @@ void nxagentVerifyDefaultFontPath(void)
XFontStruct
*
nxagentLoadQueryFont
(
register
Display
*
dpy
,
char
*
name
,
FontPtr
pFont
)
{
XFontStruct
*
fs
;
xCharInfo
*
xcip
;
fs
=
(
XFontStruct
*
)
malloc
(
sizeof
(
XFontStruct
));
XFontStruct
*
fs
=
(
XFontStruct
*
)
malloc
(
sizeof
(
XFontStruct
));
if
(
fs
==
NULL
)
{
...
...
@@ -1552,7 +1547,7 @@ XFontStruct* nxagentLoadQueryFont(register Display *dpy, char *name, FontPtr pFo
if
(
fs
->
n_properties
>
0
)
{
register
long
nbytes
;
long
nbytes
;
nbytes
=
pFont
->
info
.
nprops
*
sizeof
(
XFontProp
);
fs
->
properties
=
(
XFontProp
*
)
malloc
((
unsigned
)
nbytes
);
...
...
@@ -1570,7 +1565,7 @@ XFontStruct* nxagentLoadQueryFont(register Display *dpy, char *name, FontPtr pFo
memmove
(
fs
->
properties
,
pFont
->
info
.
props
,
nbytes
);
}
xcip
=
(
xCharInfo
*
)
&
pFont
->
info
.
ink_minbounds
;
xCharInfo
*
xcip
=
(
xCharInfo
*
)
&
pFont
->
info
.
ink_minbounds
;
fs
->
min_bounds
.
lbearing
=
cvtINT16toShort
(
xcip
->
leftSideBearing
);
fs
->
min_bounds
.
rbearing
=
cvtINT16toShort
(
xcip
->
rightSideBearing
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment