Skip to content

Commit

Permalink
Allow optional width= and height= specifiers for PROJECT_LOGO
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Dec 18, 2023
1 parent 351dba6 commit 0e92a0c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/doxygen.cpp
Expand Up @@ -9942,7 +9942,7 @@ static void copyStyleSheet()

static void copyLogo(const QCString &outputOption)
{
QCString projectLogo = Config_getString(PROJECT_LOGO);
QCString projectLogo = projectLogoFile();
if (!projectLogo.isEmpty())
{
FileInfo fi(projectLogo.str());
Expand Down
93 changes: 80 additions & 13 deletions src/util.cpp
Expand Up @@ -3435,25 +3435,92 @@ static QCString showDate(const QCString &fmt)
return formatDateTime(fmt,dat,usedFormat);
}

QCString projectLogoFile()
{
QCString projectLogo = Config_getString(PROJECT_LOGO);
if (!projectLogo.isEmpty())
{
// check for optional width= and height= specifier
int wi = projectLogo.find(" width=");
if (wi!=-1) // and strip them
{
projectLogo = projectLogo.left(wi);
}
int hi = projectLogo.find(" height=");
if (hi!=-1)
{
projectLogo = projectLogo.left(hi);
}
}
//printf("projectlogo='%s'\n",qPrint(projectLogo));
return projectLogo;
}

static QCString projectLogoSize()
{
QCString sizeVal;
QCString projectLogo = Config_getString(PROJECT_LOGO);
if (!projectLogo.isEmpty())
{
auto extractDimension = [&projectLogo](const char *startMarker,int startPos,int endPos) -> QCString
{
QCString result = projectLogo.mid(startPos,endPos-startPos).stripWhiteSpace().quoted();
if (result.length()>=2 && result.at(0)!='"' && result.at(result.length()-1)!='"')
{
result="\""+result+"\"";
}
result.prepend(startMarker);
return result;
};
// check for optional width= and height= specifier
int wi = projectLogo.find(" width=");
int hi = projectLogo.find(" height=");
if (wi!=-1 && hi!=-1)
{
if (wi<hi) // "... width=x height=y..."
{
sizeVal = extractDimension(" width=", wi+7, hi) + " "
+ extractDimension(" height=", hi+8, projectLogo.length());
}
else // "... height=y width=x..."
{
sizeVal = extractDimension(" height=", hi+8, wi) + " "
+ extractDimension(" width=", wi+7, projectLogo.length());
}
}
else if (wi!=-1) // ... width=x..."
{
sizeVal = extractDimension(" width=", wi+7, projectLogo.length());
}
else if (hi!=-1) // ... height=x..."
{
sizeVal = extractDimension(" height=", hi+8, projectLogo.length());
}
}
//printf("projectsize='%s'\n",qPrint(sizeVal));
return sizeVal;
}

QCString substituteKeywords(const QCString &s,const QCString &title,
const QCString &projName,const QCString &projNum,const QCString &projBrief)
{
return substituteKeywords(s,
{
// keyword value getter
{ "$title", [&]() { return !title.isEmpty() ? title : projName; } },
{ "$datetime", [&]() { return dateToString(DateTimeType::DateTime); } },
{ "$date", [&]() { return dateToString(DateTimeType::Date); } },
{ "$time", [&]() { return dateToString(DateTimeType::Time); } },
{ "$year", [&]() { return yearToString(); } },
{ "$doxygenversion",[&]() { return getDoxygenVersion(); } },
{ "$projectname", [&]() { return projName; } },
{ "$projectnumber", [&]() { return projNum; } },
{ "$projectbrief", [&]() { return projBrief; } },
{ "$projectlogo", [&]() { return stripPath(Config_getString(PROJECT_LOGO)); } },
{ "$projecticon", [&]() { return stripPath(Config_getString(PROJECT_ICON)); } },
{ "$langISO", [&]() { return theTranslator->trISOLang(); } },
{ "$showdate", [&](const QCString &fmt) { return showDate(fmt); } }
{ "$title", [&]() { return !title.isEmpty() ? title : projName; } },
{ "$datetime", [&]() { return dateToString(DateTimeType::DateTime); } },
{ "$date", [&]() { return dateToString(DateTimeType::Date); } },
{ "$time", [&]() { return dateToString(DateTimeType::Time); } },
{ "$year", [&]() { return yearToString(); } },
{ "$doxygenversion", [&]() { return getDoxygenVersion(); } },
{ "$projectname", [&]() { return projName; } },
{ "$projectnumber", [&]() { return projNum; } },
{ "$projectbrief", [&]() { return projBrief; } },
{ "$projectlogo", [&]() { return stripPath(projectLogoFile()); } },
{ "$logosize", [&]() { return projectLogoSize(); } },
{ "$projecticon", [&]() { return stripPath(Config_getString(PROJECT_ICON)); } },
{ "$langISO", [&]() { return theTranslator->trISOLang(); } },
{ "$showdate", [&](const QCString &fmt) { return showDate(fmt); } }
});
}

Expand Down
1 change: 1 addition & 0 deletions src/util.h
Expand Up @@ -474,5 +474,6 @@ inline QCString fixSpaces(const QCString &s) { return substitute(s," ","&#160;")
QCString detab(const QCString &s,int &refIndent);

QCString getProjectId();
QCString projectLogoFile();

#endif
2 changes: 1 addition & 1 deletion templates/html/header.html
Expand Up @@ -43,7 +43,7 @@
<tbody>
<tr id="projectrow">
<!--BEGIN PROJECT_LOGO-->
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"/></td>
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"$logosize/></td>
<!--END PROJECT_LOGO-->
<!--BEGIN PROJECT_NAME-->
<td id="projectalign">
Expand Down

0 comments on commit 0e92a0c

Please sign in to comment.