Commit 5474342e by 高宇强

gyq

parent 76520487
...@@ -46,6 +46,13 @@ def getLogoUrl(inputdata): ...@@ -46,6 +46,13 @@ def getLogoUrl(inputdata):
imagepath = pic1["name"] imagepath = pic1["name"]
font_url = 'font/cn/' + imagepath font_url = 'font/cn/' + imagepath
if type == "standard": if type == "standard":
# 获取svg的url地址
svg_url = ""
select_url = 'select pic_url from logo_svg where png_id =%s' % log_id
cur.execute(select_url)
pic2 = cur.fetchone()
if pic2:
svg_url = pic2["pic_url"]
gen_json = { gen_json = {
'brand_text': brand_text, # 品牌名称 'brand_text': brand_text, # 品牌名称
'brand_color': brand_color, # 字体颜色 'brand_color': brand_color, # 字体颜色
...@@ -53,7 +60,8 @@ def getLogoUrl(inputdata): ...@@ -53,7 +60,8 @@ def getLogoUrl(inputdata):
'slogan_text': slogan_text, # 标语名称,可以为空 'slogan_text': slogan_text, # 标语名称,可以为空
'slogan_color': slogan_color, # 标语颜色 'slogan_color': slogan_color, # 标语颜色
'logo_url': logo_url, # 图片地址 'logo_url': logo_url, # 图片地址
'brand_font': font_url # 字体路径 'brand_font': font_url, # 字体路径
'svg_url':svg_url #svg的url路径
} }
# 生成6个图片 # 生成6个图片
...@@ -76,7 +84,6 @@ def getLogoUrl(inputdata): ...@@ -76,7 +84,6 @@ def getLogoUrl(inputdata):
'brand_font': font_url, # 字体路径 'brand_font': font_url, # 字体路径
'model_id': model_id 'model_id': model_id
} }
print(str(gen_json))
pic_all = CustomizeBaseLogo.down_customize_logo(gen_json) pic_all = CustomizeBaseLogo.down_customize_logo(gen_json)
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020-05-18 14:04
# @Author : zhangyunfei
# @File : LogoParseFonts.py
# @Software: PyCharm
from fontTools.ttLib import TTFont
# 首先对字符找到对应的ASCII数值,然后去字体库里找到对应字符的unicode编码
def get_unicode(font_path, text):
try:
textlist = []
for ch in text:
ch_ascii = ord(ch)
textlist.append({'name': ch, 'ucode': ch_ascii})
# 读取字体库
font_lib = TTFont(font_path)
cmap = font_lib['cmap']
for ucode, gname in cmap.getBestCmap().items():
for tl in textlist:
if ucode == tl['ucode']:
tl['unicode'] = gname
text_count = 0
text_unicode_count = 0
for item in textlist:
if item.get('name'):
text_count += 1
if item.get('unicode') is not None:
text_unicode_count += 1
if text_count == text_unicode_count:
return True
else:
return False
except:
return False
# if __name__ == '__main__':
# brand_text = '我爱我家'
# brand_font_path = 'font/cn/白舟·侍.ttf'
# # brand_font_path = 'font/cn/华文隶书.TTF'
# brand_text_list = get_unicode(brand_font_path, brand_text)
#
# print(brand_text_list)
\ No newline at end of file
...@@ -222,6 +222,6 @@ def DeletefileApi():#删除临时文件 ...@@ -222,6 +222,6 @@ def DeletefileApi():#删除临时文件
if __name__ == '__main__': if __name__ == '__main__':
CORS(app, supports_credentials=True)#允许跨域 CORS(app, supports_credentials=True)#允许跨域
app.run(host='0.0.0.0', port=80, debug=True) # app.run(host='0.0.0.0', port=80, debug=True)
#app.run(host='127.0.0.1', port=5000, debug=True) app.run(host='127.0.0.1', port=5000, debug=True)
#!/usr/bin/env python
# Copyright 2016 Adobe. All rights reserved.
"""
Generates a set of SVG glyph files from one or more fonts and hex colors
for each of them. The fonts' format can be either OpenType, TrueType, WOFF,
or WOFF2.
"""
import os
import re
import sys
import time
import requests
from io import BytesIO
import json
#import util.check_fonttools # pylint: disable=unused-import
from fontTools import ttLib
from fontTools.pens.basePen import BasePen
from fontTools.pens.transformPen import TransformPen
class SVGPen(BasePen):
def __init__(self, glyphSet):
BasePen.__init__(self, glyphSet)
self.d = u''
self._lastX = self._lastY = None
self.xList = []
def _moveTo(self, pt):
self.xList.append(pt)
ptx, pty = self._isInt(pt)
self.d += u'M{} {}'.format(ptx, pty)
self._lastX, self._lastY = pt
def _lineTo(self, pt):
self.xList.append(pt)
ptx, pty = self._isInt(pt)
if (ptx, pty) == (self._lastX, self._lastY):
return
elif ptx == self._lastX:
self.d += u'V{}'.format(pty)
elif pty == self._lastY:
self.d += u'H{}'.format(ptx)
else:
self.d += u'L{} {}'.format(ptx, pty)
self._lastX, self._lastY = pt
def _curveToOne(self, pt1, pt2, pt3):
self.xList.append(pt1)
self.xList.append(pt2)
self.xList.append(pt3)
pt1x, pt1y = self._isInt(pt1)
pt2x, pt2y = self._isInt(pt2)
pt3x, pt3y = self._isInt(pt3)
self.d += u'C{} {} {} {} {} {}'.format(pt1x, pt1y, pt2x, pt2y,
pt3x, pt3y)
self._lastX, self._lastY = pt3
def _qCurveToOne(self, pt1, pt2):
self.xList.append(pt1)
self.xList.append(pt2)
pt1x, pt1y = self._isInt(pt1)
pt2x, pt2y = self._isInt(pt2)
self.d += u'Q{} {} {} {}'.format(pt1x, pt1y, pt2x, pt2y)
self._lastX, self._lastY = pt2
def _closePath(self):
self.d += u'Z'
self._lastX = self._lastY = None
def _endPath(self):
self._closePath()
@staticmethod
def _isInt(tup):
return [int(flt) if (flt).is_integer() else flt for flt in tup]
def processFonts(font_path):
# Load the fonts and collect their glyph sets
font = ttLib.TTFont(font_path)
print(font)
gSet = font.getGlyphSet()
print(gSet)
glyphNamesList = gSet.keys()
print(glyphNamesList)
font.close()
# Confirm that there's something to process
if not glyphNamesList:
print("The fonts and options provided can't produce any SVG files.",
file=sys.stdout)
return
web_font_dict = dict()
glyphNamesList1 =['uniFF54','uniFF55','uniFF56']
# Generate the SVGs
for gName in glyphNamesList1:
pen = SVGPen(gSet)
tpen = TransformPen(pen, (0.035, 0.0, 0.0, -0.035, -20.0, 0.0))
glyph = gSet[gName]
glyph.draw(tpen)
d = pen.d
# print(gName)
# print(d)
# Skip glyphs with no contours
if not len(d):
continue
web_font_dict[gName] = d # (gname, d)
# print(web_font_dict)
font.close()
return web_font_dict
#品牌语生成字体
def brandFont(font_path,ucodelist):
# Load the fonts and collect their glyph sets
font = ttLib.TTFont(font_path)
gSet = font.getGlyphSet()
glyphNamesList = gSet.keys()
# Confirm that there's something to process
if not glyphNamesList:
print("The fonts and options provided can't produce any SVG files.",
file=sys.stdout)
return
web_font_list = []
x = 0
boxlist = []
for gName in ucodelist:
# print(gName,'+++++++++++++++++++++++++++++++++++++++++++++')
pen = SVGPen(gSet)
tpen = TransformPen(pen, (0.028, 0.0, 0.0, -0.028, x*28.0, -8.0))
name = gName['name']
glyph = gSet[gName['unicode']]
glyph.draw(tpen)
d = pen.d
boxlist.extend(pen.xList)
# print(gName)
# print(d)
# Skip glyphs with no contours
if not len(d):
continue
web_font_list.append({'name':name,'path_d':d}) # (gname, d)
x+=1
font.close()
# print(web_font_list)
xx = []
yy = []
for it in boxlist:
xx.append(it[0])
yy.append(it[1])
righttop_x = int(max(xx))
righttop_y = int(min(yy))
righttop = (righttop_x,righttop_y)
return web_font_list,righttop
#标语生成字体
def sloganFont(font_path,ucodelist):
font = ttLib.TTFont(font_path)
gSet = font.getGlyphSet()
glyphNamesList = gSet.keys()
# Confirm that there's something to process
if not glyphNamesList:
print("The fonts and options provided can't produce any SVG files.",
file=sys.stdout)
return
web_font_list = []
x = 0
boxlist = []
for gName in ucodelist:
# print(gName, '+++++++++++++++++++++++++++++++++++++++++++++')
pen = SVGPen(gSet)
tpen = TransformPen(pen, (0.0035, 0.0, 0.0, -0.0035, x * 8.0, 6.0))
name = gName['name']
glyph = gSet[gName['unicode']]
glyph.draw(tpen)
d = pen.d
boxlist.extend(pen.xList)
# print(gName)
# print(d)
# Skip glyphs with no contours
if not len(d):
continue
web_font_list.append({'name':name,'path_d':d}) # (gname, d)
x += 1
font.close()
xx = []
yy = []
for it in boxlist:
xx.append(it[0])
yy.append(it[1])
righttop_x = int(max(xx))
righttop_y = int(max(yy))
righttop = (righttop_x, righttop_y)
return web_font_list, righttop
# if __name__ == "__main__":
# start = time.time()
# lt = [{'name': '粒', 'ucode': 31890, 'unicode': 'uni7C92'}, {'name': '子', 'ucode': 23376, 'unicode': 'uni5B50'}, {'name': '风', 'ucode': 39118, 'unicode': 'uni98CE'}, {'name': '暴', 'ucode': 26292, 'unicode': 'uni66B4'}]
# lt2 = [{'name': '厘', 'ucode': 21400, 'unicode': 'uni5398'}, {'name': '山', 'ucode': 23665, 'unicode': 'uni5C71'}, {'name': '科', 'ucode': 31185, 'unicode': 'uni79D1'}, {'name': '技', 'ucode': 25216, 'unicode': 'uni6280'}]
#
# results = brandFont('../font/cn/hwfs.ttf',lt2)
# print('time cost is: ', time.time() - start)
# print(results)
# '''
# headers = {
# 'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"
# }
# response = requests.get(url="https://" + 's3plus.meituan.net/v1/mss_73a511b8f91f43d0bdae92584ea6330b/font/53cfe63b.woff', headers=headers)
# woff_file = BytesIO()
# for chunk in response.iter_content(100000):
# woff_file.write(chunk)
# results = font2svg(woff_file)
# print(results)
# '''
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment