forked from mirrors/gecko-dev
Bug 1917742 - Share link-target escaping code between DrawTargetCairo::Link and DrawTargetCairo::Destination. a=RyanVM
Original Revision: https://phabricator.services.mozilla.com/D224319 Differential Revision: https://phabricator.services.mozilla.com/D224628
This commit is contained in:
parent
0fa5c2d37c
commit
5be904aa58
1 changed files with 21 additions and 26 deletions
|
|
@ -654,21 +654,14 @@ SurfaceFormat GfxFormatForCairoSurface(cairo_surface_t* surface) {
|
|||
return CairoContentToGfxFormat(cairo_surface_get_content(surface));
|
||||
}
|
||||
|
||||
void DrawTargetCairo::Link(const char* aDest, const char* aURI,
|
||||
const Rect& aRect) {
|
||||
if ((!aURI || !*aURI) && (!aDest || !*aDest)) {
|
||||
// No destination? Just bail out.
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to \-escape any single-quotes in the destination and URI strings,
|
||||
// in order to pass them via the attributes arg to cairo_tag_begin.
|
||||
//
|
||||
// We also need to escape any backslashes (bug 1748077), as per doc at
|
||||
// https://www.cairographics.org/manual/cairo-Tags-and-Links.html#cairo-tag-begin
|
||||
//
|
||||
// (Encoding of non-ASCII chars etc gets handled later by the PDF backend.)
|
||||
auto escapeForCairo = [](nsACString& aStr) {
|
||||
// We need to \-escape any single-quotes in the destination and URI strings,
|
||||
// in order to pass them via the attributes arg to cairo_tag_begin.
|
||||
//
|
||||
// We also need to escape any backslashes (bug 1748077), as per doc at
|
||||
// https://www.cairographics.org/manual/cairo-Tags-and-Links.html#cairo-tag-begin
|
||||
//
|
||||
// (Encoding of non-ASCII chars etc gets handled later by the PDF backend.)
|
||||
static void EscapeForCairo(nsACString& aStr) {
|
||||
for (size_t i = aStr.Length(); i > 0;) {
|
||||
--i;
|
||||
if (aStr[i] == '\'') {
|
||||
|
|
@ -677,7 +670,14 @@ void DrawTargetCairo::Link(const char* aDest, const char* aURI,
|
|||
aStr.ReplaceLiteral(i, 1, "\\\\");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void DrawTargetCairo::Link(const char* aDest, const char* aURI,
|
||||
const Rect& aRect) {
|
||||
if ((!aURI || !*aURI) && (!aDest || !*aDest)) {
|
||||
// No destination? Just bail out.
|
||||
return;
|
||||
}
|
||||
|
||||
double x = aRect.x, y = aRect.y, w = aRect.width, h = aRect.height;
|
||||
cairo_user_to_device(mContext, &x, &y);
|
||||
|
|
@ -686,12 +686,12 @@ void DrawTargetCairo::Link(const char* aDest, const char* aURI,
|
|||
|
||||
if (aDest && *aDest) {
|
||||
nsAutoCString dest(aDest);
|
||||
escapeForCairo(dest);
|
||||
EscapeForCairo(dest);
|
||||
attributes.AppendPrintf(" dest='%s'", dest.get());
|
||||
}
|
||||
if (aURI && *aURI) {
|
||||
nsAutoCString uri(aURI);
|
||||
escapeForCairo(uri);
|
||||
EscapeForCairo(uri);
|
||||
attributes.AppendPrintf(" uri='%s'", uri.get());
|
||||
}
|
||||
|
||||
|
|
@ -710,12 +710,7 @@ void DrawTargetCairo::Destination(const char* aDestination,
|
|||
}
|
||||
|
||||
nsAutoCString dest(aDestination);
|
||||
for (size_t i = dest.Length(); i > 0;) {
|
||||
--i;
|
||||
if (dest[i] == '\'') {
|
||||
dest.ReplaceLiteral(i, 1, "\\'");
|
||||
}
|
||||
}
|
||||
EscapeForCairo(dest);
|
||||
|
||||
double x = aPoint.x, y = aPoint.y;
|
||||
cairo_user_to_device(mContext, &x, &y);
|
||||
|
|
|
|||
Loading…
Reference in a new issue