public GlyphPlanSequence Layout(GlyphLayout glyphLayout, TextBuffer buffer, int startAt, int len) { //this func get the raw char from buffer //and create glyph list //check if we have the string cache in specific value //--------- if (len > _glyphPlanSeqSet.MaxCacheLen) { //layout string is too long to be cache //it need to split into small buffer } GlyphPlanSequence planSeq = GlyphPlanSequence.Empty; GlyphPlanSeqCollection seqCol = _glyphPlanSeqSet.GetSeqCollectionOrCreateIfNotExist(len); int hashValue = CalculateHash(buffer, startAt, len); if (!seqCol.TryGetCacheGlyphPlanSeq(hashValue, out planSeq)) { ////not found then create glyph plan seq //bool useOutputScale = glyphLayout.UsePxScaleOnReadOutput; ////save //some font may have 'special' glyph x,y at some font size(eg. for subpixel-rendering position) //but in general we store the new glyph plan seq with unscale glyph pos //glyphLayout.UsePxScaleOnReadOutput = false; planSeq = CreateGlyphPlanSeq(glyphLayout, buffer, startAt, len); //glyphLayout.UsePxScaleOnReadOutput = useOutputScale;//restore seqCol.Register(hashValue, planSeq); } //--- //on unscale font=> we use original return(planSeq); }
Dictionary <int, GlyphPlanSeqCollection> _cacheSeqCollection2; //lazy init public GlyphPlanSeqSet() { _cacheSeqCollection1 = new GlyphPlanSeqCollection[PREDEFINE_LEN]; this.MaxCacheLen = 20; //stop caching, please managed this ... //TODO: //what is the proper number of cache word ? //init free dic for (int i = PREDEFINE_LEN - 1; i >= 0; --i) { _cacheSeqCollection1[i] = new GlyphPlanSeqCollection(i); } }
public GlyphPlanSequence GetUnscaledGlyphPlanSequence( GlyphLayout glyphLayout, TextBuffer buffer, int start, int seqLen) { //UNSCALED VERSION //use current typeface + scriptlang int seqHashValue = CalculateHash(buffer, start, seqLen); //this func get the raw char from buffer //and create glyph list //check if we have the string cache in specific value //--------- if (seqLen > _glyphPlanSeqSet.MaxCacheLen) { //layout string is too long to be cache //it need to split into small buffer } GlyphPlanSequence planSeq = GlyphPlanSequence.Empty; GlyphPlanSeqCollection seqCol = _glyphPlanSeqSet.GetSeqCollectionOrCreateIfNotExist(seqLen); if (!seqCol.TryGetCacheGlyphPlanSeq(seqHashValue, out planSeq)) { //create a new one if we don't has a cache //1. layout glyphLayout.Layout( buffer.UnsafeGetInternalBuffer(), start, seqLen); int pre_count = _reusableGlyphPlanList.Count; //create glyph-plan ( UnScaled version) and add it to planList glyphLayout.GenerateUnscaledGlyphPlans(_reusableGlyphPlanList); int post_count = _reusableGlyphPlanList.Count; planSeq = new GlyphPlanSequence(_reusableGlyphPlanList, pre_count, post_count - pre_count); // seqCol.Register(seqHashValue, planSeq); } return(planSeq); }
public GlyphPlanSeqCollection GetSeqCollectionOrCreateIfNotExist(int len) { if (len < PREDEFINE_LEN) { return(_cacheSeqCollection1[len]); } else { if (_cacheSeqCollection2 == null) { _cacheSeqCollection2 = new Dictionary <int, GlyphPlanSeqCollection>(); } GlyphPlanSeqCollection seqCol; if (!_cacheSeqCollection2.TryGetValue(len, out seqCol)) { //new one if not exist seqCol = new GlyphPlanSeqCollection(len); _cacheSeqCollection2.Add(len, seqCol); } return(seqCol); } }