private PointF findCenter(MemeText m) { return(new PointF( (m.Width / 2) + m.XStartPosition, (m.Height / 2) + m.YStartPosition )); }
private async Task <Font> getFont(MemeText m, string text) { var fam = SystemFonts.Find("Impact"); var basefont = new Font(fam, 12, FontStyle.Bold); var imagebox = await Task.Run( () => TextMeasurer.Measure(text, new RendererOptions(basefont)) ); var yscalefactor = m.Height / imagebox.Height; var xscalefactor = m.Width / imagebox.Width; return(new Font(basefont, 12 * (xscalefactor < yscalefactor ? xscalefactor : yscalefactor))); }
public MagickReadSettings Composition(MemeText m) { return(new MagickReadSettings() { Font = "Impact", TextGravity = Gravity.Center, BackgroundColor = MagickColors.Transparent, StrokeColor = new MagickColor(m.OutlineColor), FillColor = new MagickColor(m.FillColor), Height = m.Height, Width = m.Width }); }
public async Task CreateMeme(IDialogContext context, LuisResult result) { int memetype = 0; MemeCreateOrder order = new MemeCreateOrder(); memetype = await ExtractMemeTypeReccomendationFromResult(result); memetext = await Task.Run(() => ExtractMemeTextReccomendationFromResult(result)); // got a memetype back from the reccomender? fill it in if (memetype != 0) { order.memeOptions = (PopularMemeTypes)memetype; } // got text back from the reccomendation engine? fill that in too if ((memetext.TopText != string.Empty) || (memetext.BottomText != string.Empty)) { // check if the meme text entity reccomendations came back with anything. If the user used pre-filling syntaxt intents // then we should just pass those in to the order order.toptext = (memetext.TopText == String.Empty) ? null : memetext.TopText; order.bottomtext = (memetext.BottomText == String.Empty) ? null : memetext.BottomText; } // if at this point we have enough information to create the meme without prompts, we bypass // the interactive conversation and just go if (order.HasEnoughInformationToCreateMeme) { Activity reply = context.MakeMessage() as Activity; await CaptionService.GenerateResultForMemeCreate(memetype, memetext.TopText, memetext.BottomText, reply); await context.PostAsync(reply); context.Wait(MessageReceived); } // otherwise, spin the converation from where we are (starting from whatever point we're at) else { IFormDialog <MemeCreateOrder> createOrderDialog = MakeMemeCreateInteractiveDialog(order); context.Call(createOrderDialog, FinalizeMemeCreation); } }
/// <summary> /// Extracts the memetext from a luis result object /// </summary> /// <param name="result">the LUIS result object to inspect</param> /// <returns></returns> private MemeText ExtractMemeTextReccomendationFromResult(LuisResult result) { EntityRecommendation memetexttop; EntityRecommendation memetextbottom; MemeText returnMemeTextObject = new MemeText(); // Look for the top text and bottom text reccomendation first // if both don't have values, only then look for a the entity reccomendation for generalized text if (!result.TryFindEntity(ENTITY_MEME_TEXT_TOP, out memetexttop)) { memetexttop = new EntityRecommendation(ENTITY_MEME_TEXT) { Entity = "" }; } if (!result.TryFindEntity(ENTITY_MEME_TEXT_BOTTOM, out memetextbottom)) { memetextbottom = new EntityRecommendation(ENTITY_MEME_TEXT) { Entity = "" }; } // only in this case do we check the general entity reccomendation field if ((memetextbottom.Entity == "") && (memetexttop.Entity == "")) { // if we do find something put it the bottom text field if (!result.TryFindEntity(ENTITY_MEME_TEXT, out memetextbottom)) { memetextbottom = new EntityRecommendation(ENTITY_MEME_TEXT) { Entity = "" }; } } returnMemeTextObject.TopText = memetexttop.Entity; returnMemeTextObject.BottomText = memetextbottom.Entity; return(returnMemeTextObject); }