Serve fonts from Gerrit instead of Google Fonts.
Bug: Issue 3985 Change-Id: I107921c7e1fbc02e3b279f4d834c16447dffde51
This commit is contained in:
parent
9ea5055242
commit
5eb59e374e
@ -0,0 +1,61 @@
|
||||
// Copyright (C) 2016 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.httpd.raw;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.gerrit.launcher.GerritLauncher;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
class FontsServlet extends ResourceServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Path zip;
|
||||
private final Path fonts;
|
||||
|
||||
FontsServlet(Cache<Path, Resource> cache, Path buckOut)
|
||||
throws IOException {
|
||||
super(cache, true);
|
||||
zip = getZipPath(buckOut);
|
||||
if (zip == null || !Files.exists(zip)) {
|
||||
fonts = null;
|
||||
} else {
|
||||
fonts = GerritLauncher
|
||||
.newZipFileSystem(zip)
|
||||
.getPath("/");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Path getResourcePath(String pathInfo) throws IOException {
|
||||
if (fonts == null) {
|
||||
throw new IOException("No fonts found: " + zip
|
||||
+ ". Run `buck build //polygerrit-ui:fonts`?");
|
||||
}
|
||||
return fonts.resolve(pathInfo);
|
||||
}
|
||||
|
||||
private static Path getZipPath(Path buckOut) {
|
||||
if (buckOut == null) {
|
||||
return null;
|
||||
}
|
||||
return buckOut.resolve("gen")
|
||||
.resolve("polygerrit-ui")
|
||||
.resolve("fonts")
|
||||
.resolve("fonts.zip");
|
||||
}
|
||||
}
|
@ -221,10 +221,11 @@ public class StaticModule extends ServletModule {
|
||||
Path buckOut = getPaths().buckOut;
|
||||
if (buckOut != null) {
|
||||
serve("/bower_components/*").with(BowerComponentsServlet.class);
|
||||
serve("/fonts/*").with(FontsServlet.class);
|
||||
} else {
|
||||
// In the war case, bower_components are either inlined by vulcanize, or
|
||||
// live under /polygerrit_ui in the war file, so we don't need a
|
||||
// separate servlet.
|
||||
// In the war case, bower_components and fonts are either inlined
|
||||
// by vulcanize, or live under /polygerrit_ui in the war file,
|
||||
// so we don't need a separate servlet.
|
||||
}
|
||||
|
||||
Key<HttpServlet> indexKey = named(POLYGERRIT_INDEX_SERVLET);
|
||||
@ -259,6 +260,13 @@ public class StaticModule extends ServletModule {
|
||||
return new BowerComponentsServlet(cache, getPaths().buckOut);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
FontsServlet getFontsServlet(
|
||||
@Named(CACHE) Cache<Path, Resource> cache) throws IOException {
|
||||
return new FontsServlet(cache, getPaths().buckOut);
|
||||
}
|
||||
|
||||
private Path polyGerritBasePath() {
|
||||
Paths p = getPaths();
|
||||
if (options.forcePolyGerritDev()) {
|
||||
|
1
lib/BUCK
1
lib/BUCK
@ -16,6 +16,7 @@ define_license(name = 'jgit')
|
||||
define_license(name = 'jsch')
|
||||
define_license(name = 'MPL1.1')
|
||||
define_license(name = 'moment')
|
||||
define_license(name = 'OFL1.1')
|
||||
define_license(name = 'ow2')
|
||||
define_license(name = 'page.js')
|
||||
define_license(name = 'polymer')
|
||||
|
93
lib/LICENSE-OFL1.1
Normal file
93
lib/LICENSE-OFL1.1
Normal file
@ -0,0 +1,93 @@
|
||||
Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
|
||||
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
30
lib/fonts/BUCK
Normal file
30
lib/fonts/BUCK
Normal file
@ -0,0 +1,30 @@
|
||||
# Source Code Pro. Version 2.010 Roman / 1.030 Italics
|
||||
# https://github.com/adobe-fonts/source-code-pro/releases/tag/2.010R-ro%2F1.030R-it
|
||||
genrule(
|
||||
name = 'sourcecodepro',
|
||||
cmd = 'zip -rq $OUT .',
|
||||
srcs = [
|
||||
'SourceCodePro-Regular.otf.woff',
|
||||
'SourceCodePro-Regular.otf.woff2'
|
||||
],
|
||||
out = 'sourcecodepro.zip',
|
||||
license = 'OFL1.1',
|
||||
visibility = ['PUBLIC'],
|
||||
)
|
||||
|
||||
# Open Sans at Revision 53a5266 and converted using a Google woff file
|
||||
# converter (same one that Google Fonts uses).
|
||||
# https://github.com/google/fonts/tree/master/apache/opensans
|
||||
genrule(
|
||||
name = 'opensans',
|
||||
cmd = 'zip -rq $OUT .',
|
||||
srcs = [
|
||||
'OpenSans-Bold.woff',
|
||||
'OpenSans-Bold.woff2',
|
||||
'OpenSans-Regular.woff',
|
||||
'OpenSans-Regular.woff2'
|
||||
],
|
||||
out = 'opensans.zip',
|
||||
license = 'Apache2.0',
|
||||
visibility = ['PUBLIC'],
|
||||
)
|
BIN
lib/fonts/OpenSans-Bold.woff
Normal file
BIN
lib/fonts/OpenSans-Bold.woff
Normal file
Binary file not shown.
BIN
lib/fonts/OpenSans-Bold.woff2
Normal file
BIN
lib/fonts/OpenSans-Bold.woff2
Normal file
Binary file not shown.
BIN
lib/fonts/OpenSans-Regular.woff
Normal file
BIN
lib/fonts/OpenSans-Regular.woff
Normal file
Binary file not shown.
BIN
lib/fonts/OpenSans-Regular.woff2
Normal file
BIN
lib/fonts/OpenSans-Regular.woff2
Normal file
Binary file not shown.
BIN
lib/fonts/SourceCodePro-Regular.otf.woff
Normal file
BIN
lib/fonts/SourceCodePro-Regular.otf.woff
Normal file
Binary file not shown.
BIN
lib/fonts/SourceCodePro-Regular.otf.woff2
Normal file
BIN
lib/fonts/SourceCodePro-Regular.otf.woff2
Normal file
Binary file not shown.
2
polygerrit-ui/.gitignore
vendored
2
polygerrit-ui/.gitignore
vendored
@ -1,6 +1,6 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
dist
|
||||
bower.json
|
||||
fonts
|
||||
bower_components
|
||||
.tmp
|
||||
|
@ -16,3 +16,18 @@ bower_components(
|
||||
'//lib/js:promise-polyfill',
|
||||
],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = 'fonts',
|
||||
cmd = ' && '.join([
|
||||
'cd $TMP',
|
||||
'for file in $SRCS; do unzip -q $file; done',
|
||||
'zip -q $OUT *',
|
||||
]),
|
||||
srcs = [
|
||||
'//lib/fonts:sourcecodepro',
|
||||
'//lib/fonts:opensans',
|
||||
],
|
||||
out = 'fonts.zip',
|
||||
visibility = ['PUBLIC'],
|
||||
)
|
||||
|
@ -26,7 +26,8 @@ genrule(
|
||||
cmd = ' && '.join([
|
||||
'mkdir $TMP/polygerrit_ui',
|
||||
'cd $TMP/polygerrit_ui',
|
||||
'mkdir -p {elements,bower_components/webcomponentsjs}',
|
||||
'mkdir -p {fonts,elements,bower_components/webcomponentsjs}',
|
||||
'unzip -qd fonts $(location //polygerrit-ui:fonts)',
|
||||
'unzip -qd elements $(location :gr-app)',
|
||||
'cp -rp $SRCDIR/* .',
|
||||
'unzip -p $(location //polygerrit-ui:polygerrit_components) %s>%s' % (WEBJS, WEBJS),
|
||||
@ -49,7 +50,6 @@ vulcanize(
|
||||
components = '//polygerrit-ui:polygerrit_components',
|
||||
)
|
||||
|
||||
|
||||
bower_components(
|
||||
name = 'test_components',
|
||||
deps = [
|
||||
|
160
polygerrit-ui/app/styles/fonts.css
Normal file
160
polygerrit-ui/app/styles/fonts.css
Normal file
@ -0,0 +1,160 @@
|
||||
/* cyrillic-ext */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans'), local('OpenSans'),
|
||||
url(../fonts/OpenSans-Regular.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Regular.woff) format('woff');
|
||||
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
|
||||
}
|
||||
/* cyrillic */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans'), local('OpenSans'),
|
||||
url(../fonts/OpenSans-Regular.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Regular.woff) format('woff');
|
||||
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
||||
}
|
||||
/* greek-ext */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans'), local('OpenSans'),
|
||||
url(../fonts/OpenSans-Regular.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Regular.woff) format('woff');
|
||||
unicode-range: U+1F00-1FFF;
|
||||
}
|
||||
/* greek */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans'), local('OpenSans'),
|
||||
url(../fonts/OpenSans-Regular.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Regular.woff) format('woff');
|
||||
unicode-range: U+0370-03FF;
|
||||
}
|
||||
/* vietnamese */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans'), local('OpenSans'),
|
||||
url(../fonts/OpenSans-Regular.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Regular.woff) format('woff');
|
||||
unicode-range: U+0102-0103, U+1EA0-1EF1, U+20AB;
|
||||
}
|
||||
/* latin-ext */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans'), local('OpenSans'),
|
||||
url(../fonts/OpenSans-Regular.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Regular.woff) format('woff');
|
||||
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
|
||||
}
|
||||
/* latin */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Open Sans'), local('OpenSans'),
|
||||
url(../fonts/OpenSans-Regular.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Regular.woff) format('woff');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
|
||||
}
|
||||
/* cyrillic-ext */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: local('Open Sans Bold'), local('OpenSans-Bold'),
|
||||
url(../fonts/OpenSans-Bold.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Bold.woff) format('woff');
|
||||
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
|
||||
}
|
||||
/* cyrillic */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: local('Open Sans Bold'), local('OpenSans-Bold'),
|
||||
url(../fonts/OpenSans-Bold.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Bold.woff) format('woff');
|
||||
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
||||
}
|
||||
/* greek-ext */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: local('Open Sans Bold'), local('OpenSans-Bold'),
|
||||
url(../fonts/OpenSans-Bold.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Bold.woff) format('woff');
|
||||
unicode-range: U+1F00-1FFF;
|
||||
}
|
||||
/* greek */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: local('Open Sans Bold'), local('OpenSans-Bold'),
|
||||
url(../fonts/OpenSans-Bold.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Bold.woff) format('woff');
|
||||
unicode-range: U+0370-03FF;
|
||||
}
|
||||
/* vietnamese */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: local('Open Sans Bold'), local('OpenSans-Bold'),
|
||||
url(../fonts/OpenSans-Bold.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Bold.woff) format('woff');
|
||||
unicode-range: U+0102-0103, U+1EA0-1EF1, U+20AB;
|
||||
}
|
||||
/* latin-ext */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: local('Open Sans Bold'), local('OpenSans-Bold'),
|
||||
url(../fonts/OpenSans-Bold.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Bold.woff) format('woff');
|
||||
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
|
||||
}
|
||||
/* latin */
|
||||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: local('Open Sans Bold'), local('OpenSans-Bold'),
|
||||
url(../fonts/OpenSans-Bold.woff2) format('woff2'),
|
||||
url(../fonts/OpenSans-Bold.woff) format('woff');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
|
||||
}
|
||||
/* latin-ext */
|
||||
@font-face {
|
||||
font-family: 'Source Code Pro';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Source Code Pro'), local('SourceCodePro-Regular'),
|
||||
url(../fonts/SourceCodePro-Regular.otf.woff2) format('woff2'),
|
||||
url(../fonts/SourceCodePro-Regular.otf.woff) format('woff');
|
||||
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
|
||||
}
|
||||
/* latin */
|
||||
@font-face {
|
||||
font-family: 'Source Code Pro';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Source Code Pro'), local('SourceCodePro-Regular'),
|
||||
url(../fonts/SourceCodePro-Regular.otf.woff2) format('woff2'),
|
||||
url(../fonts/SourceCodePro-Regular.otf.woff) format('woff');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
|
||||
}
|
@ -14,8 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
@import "//fonts.googleapis.com/css?family=Open+Sans:400,700";
|
||||
@import "//fonts.googleapis.com/css?family=Source+Code+Pro";
|
||||
@import "fonts.css";
|
||||
|
||||
*,
|
||||
*::after,
|
||||
|
@ -23,9 +23,14 @@ if [[ ! -f .buckconfig ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
buck build //polygerrit-ui/app:polygerrit_tests
|
||||
buck build \
|
||||
//polygerrit-ui/app:test_components \
|
||||
//polygerrit-ui:fonts
|
||||
|
||||
cd polygerrit-ui/app
|
||||
rm -rf bower_components
|
||||
unzip -q ../../buck-out/gen/polygerrit-ui/app/test_components/test_components.bower_components.zip
|
||||
rm -rf fonts
|
||||
unzip -q ../../buck-out/gen/polygerrit-ui/fonts/fonts.zip -d fonts
|
||||
cd ..
|
||||
exec go run server.go "$@"
|
||||
|
Loading…
x
Reference in New Issue
Block a user