preliminary support for fiddle font use

BUG=skia:2998
TBR=jcgregorio, tfarina

Review URL: https://codereview.chromium.org/639833003
This commit is contained in:
Greg Humphreys 2014-10-08 11:09:21 -04:00
parent 47326ab5bb
commit ebca225b48
3 changed files with 24 additions and 6 deletions

View File

@ -18,7 +18,9 @@ PATH=$PATH:$GOROOT/bin
cd ${SKIA_ROOT}/include
echo "Creating compile template..."
find core effects pathops -maxdepth 1 -name "*.h" | sed "s#^[^\/]*\/##g" | sed "s/\(.*\)/#include \"\1\"/" | sort > ${WEBTRY_ROOT}/templates/template.cpp
find core effects pathops -maxdepth 1 -name "*.h" | sed "s/.*\///" | sed "s/\(.*\)/#include \"\1\"/" | sort > ${WEBTRY_ROOT}/templates/template.cpp
echo '#include "sk_tool_utils.h"' >> ${WEBTRY_ROOT}/templates/template.cpp
echo '' >> ${WEBTRY_ROOT}/templates/template.cpp
echo "SkBitmap source;" >> ${WEBTRY_ROOT}/templates/template.cpp
echo "{{.Code}}" >> ${WEBTRY_ROOT}/templates/template.cpp
cd ${WEBTRY_ROOT}

View File

@ -12,7 +12,9 @@
'type': 'executable',
'dependencies': [
'skia_lib.gyp:skia_lib',
'flags.gyp:flags'
'flags.gyp:flags',
'tools.gyp:sk_tool_utils'
],
'include_dirs': [
'../include/config',

View File

@ -36,7 +36,6 @@ import (
)
const (
DEFAULT_SAMPLE = `void draw(SkCanvas* canvas) {
SkPaint p;
p.setColor(SK_ColorRED);
@ -368,14 +367,29 @@ func expandToFile(filename string, code string, t *template.Template) error {
// expandCode expands the template into a file and calculates the MD5 hash.
func expandCode(code string, source int) (string, error) {
// in order to support fonts in the chroot jail, we need to make sure
// we're using portable typefaces.
// TODO(humper): Make this more robust, supporting things like setTypeface
inputCodeLines := strings.Split(code, "\n")
outputCodeLines := []string{}
for _, line := range inputCodeLines {
outputCodeLines = append(outputCodeLines, line)
if strings.HasPrefix(strings.TrimSpace(line), "SkPaint ") {
outputCodeLines = append(outputCodeLines, "sk_tool_utils::set_portable_typeface(&p);")
}
}
fontFriendlyCode := strings.Join(outputCodeLines, "\n")
h := md5.New()
h.Write([]byte(code))
h.Write([]byte(fontFriendlyCode))
binary.Write(h, binary.LittleEndian, int64(source))
hash := fmt.Sprintf("%x", h.Sum(nil))
// At this point we are running in skia/experimental/webtry, making cache a
// peer directory to skia.
// TODO(jcgregorio) Make all relative directories into flags.
err := expandToFile(fmt.Sprintf("../../../cache/src/%s.cpp", hash), code, codeTemplate)
err := expandToFile(fmt.Sprintf("../../../cache/src/%s.cpp", hash), fontFriendlyCode, codeTemplate)
return hash, err
}
@ -817,7 +831,7 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
cmd := "scripts/fiddle_wrapper " + hash
if *useChroot {
cmd = "schroot -c webtry --directory=/ -- /skia_build/skia/experimental/webtry/" + cmd
}
}
if request.Source > 0 {
cmd += fmt.Sprintf(" image-%d.png", request.Source)
}