Exemplo n.º 1
0
        /// <summary>
        /// 构建多个字体库
        /// </summary>
        /// <param name="apiKey">用户的apikey</param>
        /// <param name="fontIds">字体ID数组</param>
        /// <param name="content">需要处理的文本</param>
        /// <returns></returns>
        private List <WebFontInfo> Multbuild(string apiKey, int[] fontIds, string content)
        {
            MultFontBuildRequest buildRequest = new MultFontBuildRequest();

            foreach (var fontId in fontIds)
            {
                buildRequest.Items.Add(new FontBuildRequest
                {
                    Apikey   = apiKey,
                    FontId   = (uint)fontId,
                    Text     = content,
                    NeedTtf  = true,
                    NeedEot  = true,
                    NeedWoff = true
                });
            }

            try
            {
                var response        = _client.MultBuildFont(buildRequest);
                var webFontInfoList = new List <WebFontInfo>();
                foreach (var item in response.Items)
                {
                    webFontInfoList.Add(new WebFontInfo
                    {
                        fontId            = (int)item.FontId,
                        content           = content,
                        apiKey            = apiKey,
                        fontCheckSum      = (long)item.FontChecksum,
                        fontFormatVersion = (int)item.FontFormatVersion,
                        nameEn            = item.NameEn,
                        bytesTtf          = item.BytesTtf.ToByteArray(),
                        bytesEot          = item.BytesEot.ToByteArray(),
                        bytesWoff         = item.BytesWoff.ToByteArray()
                    });

                    _logger.Log(LogLevel.Information, "success build font:{0}", item.FontId);
                    _logger.Log(LogLevel.Information, "ttf len:{0}", item.BytesTtf.Length);
                    _logger.Log(LogLevel.Information, "eot len:{0}", item.BytesEot.Length);
                    _logger.Log(LogLevel.Information, "woff len:{0}", item.BytesWoff.Length);
                }

                return(webFontInfoList);
            }
            catch (Exception e)
            {
                _logger.Log(LogLevel.Warning, "RPC failed: {0}  Desc: {1}", new Object[] { e.Message, e.StackTrace });
                return(null);
            }
        }